Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tilman Marquart
Art Structures - LME Praktikum
Commits
c9206758
Unverified
Commit
c9206758
authored
Jan 11, 2020
by
tilman
Browse files
make some test with filters on bdcn image
parent
961ab0b2
Changes
5
Show whitespace changes
Inline
Side-by-side
detect_structures.py
View file @
c9206758
...
...
@@ -14,26 +14,28 @@ from lib.triangles import *
from
lib.bisection
import
*
from
lib.misc
import
*
SHOW_WINDOW
=
Fals
e
SHOW_WINDOW
=
Tru
e
SAVE_FILE
=
not
SHOW_WINDOW
SAVE_BDCN
=
True
SAVE_BDCN
=
False
BDCN_EDGES
=
True
WHITE_OUTPUT_CANVAS
=
True
TRIANGLES
=
False
BODY_LINES
=
True
BISEC_VECTORS
=
False
BISEC_CONES
=
True
GLOBAL_LINE
=
True
DRAW_FIRST_CONE_LAYER_BRIGTHER
=
True
BISEC_CONE_ANGLE
=
50
CORRECTION_ANGLE
=
23
OVERLAY_ALPHA
=
0.2
BISEC_SKIP_LOWER_LEVELS
=
Tru
e
BISEC_SKIP_LOWER_LEVELS
=
Fals
e
DISPLAY_RASTER_ELEMENTS
=
500
BDCN_EDGES
=
True
OUT_DIR
=
'images/out/images_imdahl/main_structure_final_canvas'
#IN_DIR = "images/first_email/" # images from first email
IN_DIR
=
"images/images_imdahl/"
# images from imdahl
IN_DIR_BDCN
=
"images/out/images_imdahl/bdcn_output/"
SKIP_OPENPOSE
=
Fals
e
SKIP_OPENPOSE
=
Tru
e
OPENPOSE_DEMO_KEYPOINTS
=
np
.
array
([[[
4.7613028e+02
,
3.3695804e+02
,
9.0203685e-01
],[
5.3667474e+02
,
3.8633786e+02
,
6.6615295e-01
],[
5.1645105e+02
,
3.8405157e+02
,
5.1514143e-01
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
5.5459924e+02
,
3.8859457e+02
,
6.4240879e-01
],[
5.6353766e+02
,
4.7384988e+02
,
1.8810490e-01
],[
5.3886292e+02
,
5.2543573e+02
,
9.0144195e-02
],[
5.4566248e+02
,
5.3215259e+02
,
3.6083767e-01
],[
5.2768524e+02
,
5.3213129e+02
,
3.1196830e-01
],[
5.4556714e+02
,
6.3534674e+02
,
1.8182488e-01
],[
5.8149310e+02
,
7.2958716e+02
,
1.3625422e-01
],[
5.6579541e+02
,
5.3216382e+02
,
3.6866242e-01
],[
5.8822272e+02
,
6.2862476e+02
,
1.7708556e-01
],[
6.0843213e+02
,
7.2955762e+02
,
2.2736737e-01
],[
4.7597812e+02
,
3.2798129e+02
,
5.7176876e-01
],[
4.8729745e+02
,
3.3027243e+02
,
9.1296065e-01
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
5.2090784e+02
,
3.3472034e+02
,
7.7942842e-01
],[
5.7928674e+02
,
7.5646222e+02
,
2.0351715e-01
],[
5.9049512e+02
,
7.5648248e+02
,
2.0819387e-01
],[
6.2183606e+02
,
7.3853394e+02
,
1.7312977e-01
],[
5.8145673e+02
,
7.5420642e+02
,
1.2660497e-01
],[
5.7701074e+02
,
7.5417773e+02
,
1.2881383e-01
],[
5.8374255e+02
,
7.3627380e+02
,
9.4869599e-02
]]
,[[
6.4435681e+02
,
3.6383255e+02
,
8.9096022e-01
],[
6.6903070e+02
,
3.9760306e+02
,
8.7681645e-01
],[
6.4430103e+02
,
3.9525812e+02
,
7.9584122e-01
],[
6.3310535e+02
,
4.5589160e+02
,
3.7108111e-01
],[
5.9046979e+02
,
4.2451276e+02
,
4.0277350e-01
],[
6.9366602e+02
,
4.0197583e+02
,
8.9528430e-01
],[
6.8247137e+02
,
4.6042902e+02
,
5.5132395e-01
],[
6.0616620e+02
,
4.3569894e+02
,
3.4303352e-01
],[
6.5551196e+02
,
5.1196445e+02
,
2.9572365e-01
],[
6.3529651e+02
,
5.0747903e+02
,
2.8629595e-01
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
6.7573169e+02
,
5.1421967e+02
,
3.0180413e-01
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
6.4206000e+02
,
3.5276721e+02
,
7.2430253e-01
],[
6.5327673e+02
,
3.5271103e+02
,
9.4265050e-01
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
6.7577380e+02
,
3.5269864e+02
,
8.9672232e-01
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
]]
,[[
7.2723553e+02
,
4.0875150e+02
,
8.3982950e-01
],[
7.6091986e+02
,
4.6032086e+02
,
5.0676465e-01
],[
7.3178253e+02
,
4.5359366e+02
,
3.5797939e-01
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
7.8784674e+02
,
4.6483188e+02
,
5.6356871e-01
],[
7.6320721e+02
,
5.6802844e+02
,
3.7939239e-01
],[
7.2953772e+02
,
5.4564911e+02
,
1.5424372e-01
],[
7.6546356e+02
,
6.1964557e+02
,
1.7308682e-01
],[
7.3854327e+02
,
6.1513757e+02
,
1.5351829e-01
],[
7.3855487e+02
,
7.3405249e+02
,
5.6986582e-02
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
7.8789227e+02
,
6.2636108e+02
,
1.8666090e-01
],[
7.9010718e+02
,
7.5197815e+02
,
9.0752751e-02
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
7.2722571e+02
,
3.9980579e+02
,
4.9854943e-01
],[
7.4074554e+02
,
4.0420221e+02
,
8.2562774e-01
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
7.6537799e+02
,
4.0880304e+02
,
6.8228495e-01
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
],[
0.0000000e+00
,
0.0000000e+00
,
0.0000000e+00
]]
...
...
@@ -55,6 +57,7 @@ def overlay_two_image_v2(image, overlay, ignore_color=[0,0,0], alpha=0.1):
params
=
dict
()
#params["model_folder"] = "/Users/Tilman/Documents/Programme/Python/forschungspraktikum/openpose/models/"
params
[
"model_folder"
]
=
os
.
environ
[
'OPENPOSE_MODELS'
]
#https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/output.md#pose-output-format-body_25
# Starting OpenPose
if
not
SKIP_OPENPOSE
:
...
...
@@ -69,11 +72,14 @@ images_bdcn.sort()
os
.
chdir
(
OUT_DIR
)
#save images in this dir
#for img_name in images:
for
img_name
,
img_bdcn
in
list
(
zip
(
images
,
images_bdcn
)):
# for img_name, img_bdcn in list(zip(images, images_bdcn)):
# for img_name, img_bdcn in list(zip(images, images_bdcn)):
for
img_name
,
img_bdcn
in
list
(
zip
(
images
,
images_bdcn
))[
15
:
16
]:
#jesus
# for img_name, img_bdcn in list(zip(images, images_bdcn))[6:7]: #fusswaschung
# Process Image
print
(
"calculating: "
+
img_name
)
img
=
cv2
.
imread
(
img_name
)
bdcn
=
cv2
.
imread
(
img_bdcn
)
img_output_canvas
=
np
.
array
([[[
255
,
255
,
255
]]
*
len
(
img
[
0
])]
*
len
(
img
),
np
.
uint8
)
if
WHITE_OUTPUT_CANVAS
else
cv2
.
imread
(
img_bdcn
)
max_lw
=
max
(
len
(
img
),
len
(
img
[
0
]))
esz
=
max_lw
/
DISPLAY_RASTER_ELEMENTS
if
SKIP_OPENPOSE
:
...
...
@@ -87,8 +93,8 @@ for img_name, img_bdcn in list(zip(images, images_bdcn)):
img
=
datum
.
cvOutputData
if
BDCN_EDGES
:
overlay
=
np
.
array
([[[
255
,
255
,
255
]]
*
len
(
img
[
0
])]
*
len
(
img
))
#white image canvas
bdcn
=
overlay_two_image_v2
(
bdcn
,
overlay
,
[
0
,
0
,
0
],
0.2
)
overlay
=
np
.
array
([[[
255
,
255
,
255
]]
*
len
(
img
[
0
])]
*
len
(
img
)
,
np
.
uint8
)
#white image canvas
output_canvas
=
overlay_two_image_v2
(
img_output_canvas
,
overlay
,
[
0
,
0
,
0
],
0.2
)
fposes
=
np
.
array
([
np
.
array
([
line
[:
2
]
for
line
in
pose
if
line
[
2
]
>
0
])
for
pose
in
datum
.
poseKeypoints
])
#filtered poses without zero lines
for
pose
in
fposes
:
convexhull
=
Polygon
(
pose
).
convex_hull
...
...
@@ -97,11 +103,23 @@ for img_name, img_bdcn in list(zip(images, images_bdcn)):
#cv2.line(img, (int(pose[0][0]),int(pose[0][1])), (int(pose[1][0]),int(pose[1][1])), (0,255,0), int(6*esz))
# cv2.drawContours(img, [polyToArr(sconvexhull)], 0, 255, int(10*esz))
# cv2.drawContours(img, [polyToArr(sconvexhull)], 0, 255, -1)
cv2
.
drawContours
(
bdcn
,
[
polyToArr
(
sconvexhull
)],
0
,
(
255
,
255
,
255
),
int
(
10
*
esz
))
cv2
.
drawContours
(
bdcn
,
[
polyToArr
(
sconvexhull
)],
0
,
(
255
,
255
,
255
),
-
1
)
cv2
.
drawContours
(
output_canvas
,
[
polyToArr
(
sconvexhull
)],
0
,
(
255
,
255
,
255
),
int
(
10
*
esz
))
cv2
.
drawContours
(
output_canvas
,
[
polyToArr
(
sconvexhull
)],
0
,
(
255
,
255
,
255
),
-
1
)
#draw rectangle
# cv2.rectangle(img, (0,0), (len(img[0]),len(img)), (255,0,0), int(40*esz))
cv2
.
rectangle
(
bdcn
,
(
0
,
0
),
(
len
(
img
[
0
]),
len
(
img
)),
(
255
,
255
,
255
),
int
(
40
*
esz
))
cv2
.
rectangle
(
output_canvas
,
(
0
,
0
),
(
len
(
img
[
0
]),
len
(
img
)),
(
255
,
255
,
255
),
int
(
40
*
esz
))
if
TRIANGLES
or
BODY_LINES
:
triangles
=
[
poseToTriangle
(
pose
)
for
pose
in
datum
.
poseKeypoints
]
for
triangle
in
triangles
:
if
triangle
is
not
None
:
if
TRIANGLES
:
cv2
.
drawContours
(
img
,
[
triangle
],
0
,
255
,
-
1
)
cv2
.
drawContours
(
output_canvas
,
[
triangle
],
0
,
255
,
-
1
)
if
BODY_LINES
:
linePoints
=
triangleToBodyLine
(
triangle
)
cv2
.
line
(
img
,
trp
(
linePoints
[
0
]),
trp
(
linePoints
[
1
]),
(
0
,
255
,
0
),
int
(
6
*
esz
))
cv2
.
line
(
output_canvas
,
trp
(
linePoints
[
0
]),
trp
(
linePoints
[
1
]),
(
0
,
255
,
0
),
int
(
6
*
esz
))
if
BISEC_CONES
or
GLOBAL_LINE
:
bisecCones
=
[
poseToBisectCone
(
pose
,
max_lw
,
BISEC_CONE_ANGLE
,
CORRECTION_ANGLE
)
for
pose
in
datum
.
poseKeypoints
]
#use max(img.height,width) as cone length
...
...
@@ -115,10 +133,14 @@ for img_name, img_bdcn in list(zip(images, images_bdcn)):
continue
;
else
:
overlay
=
np
.
zeros
((
len
(
img
),
len
(
img
[
0
]),
3
),
np
.
uint8
)
color
=
min
(((
len
(
combi
)
-
1
)
*
150
,
255
))
color
=
min
(((
len
(
combi
)
-
1
)
*
100
,
255
))
alpha
=
OVERLAY_ALPHA
if
DRAW_FIRST_CONE_LAYER_BRIGTHER
and
len
(
combi
)
==
1
:
cv2
.
drawContours
(
overlay
,
[
polyToArr
(
intersections
[
combi
])],
0
,
(
0
,
255
,
0
),
-
1
)
img
=
overlay_two_image_v2
(
img
,
overlay
,
[
0
,
0
,
0
],
(
0.25
))
if
BISEC_CONES
:
cv2
.
drawContours
(
overlay
,
[
polyToArr
(
intersections
[
combi
])],
0
,
(
color
,
0
,(
0
if
is_not_last_level
else
255
)),
-
1
)
img
=
overlay_two_image_v2
(
img
,
overlay
,
[
0
,
0
,
0
],
(
OVERLAY_ALPHA
if
is_not_last_level
else
0.6
))
img
=
overlay_two_image_v2
(
img
,
overlay
,
[
0
,
0
,
0
],
(
alpha
if
is_not_last_level
else
0.6
))
if
not
is_not_last_level
and
GLOBAL_LINE
:
#draw centroid of last polygon
xy
=
(
int
(
intersections
[
combi
].
centroid
.
x
),
int
(
intersections
[
combi
].
centroid
.
y
))
global_angle
=
getGlobalLineAngle
(
datum
.
poseKeypoints
,
CORRECTION_ANGLE
)
...
...
@@ -128,42 +150,30 @@ for img_name, img_bdcn in list(zip(images, images_bdcn)):
d_l
=
(
int
(
-
dist
*
np
.
cos
(
global_angle
)),
int
(
-
dist
*
np
.
sin
(
global_angle
)))
#with origin zero
# draw line with global gaze angle (special mean of all gaze angles) and through center of last intersection
cv2
.
line
(
img
,
xy
,
(
xy
[
0
]
+
d
[
0
],
xy
[
1
]
-
d
[
1
]),
(
0
,
255
,
255
),
int
(
10
*
esz
))
cv2
.
line
(
bdcn
,
xy
,
(
xy
[
0
]
+
d
[
0
],
xy
[
1
]
-
d
[
1
]),
(
0
,
255
,
255
),
int
(
10
*
esz
))
cv2
.
line
(
output_canvas
,
xy
,
(
xy
[
0
]
+
d
[
0
],
xy
[
1
]
-
d
[
1
]),
(
0
,
255
,
255
),
int
(
10
*
esz
))
cv2
.
line
(
img
,
xy
,
(
xy
[
0
]
+
d_l
[
0
],
xy
[
1
]
-
d_l
[
1
]),
(
0
,
255
,
255
),
int
(
10
*
esz
))
cv2
.
line
(
bdcn
,
xy
,
(
xy
[
0
]
+
d_l
[
0
],
xy
[
1
]
-
d_l
[
1
]),
(
0
,
255
,
255
),
int
(
10
*
esz
))
cv2
.
line
(
output_canvas
,
xy
,
(
xy
[
0
]
+
d_l
[
0
],
xy
[
1
]
-
d_l
[
1
]),
(
0
,
255
,
255
),
int
(
10
*
esz
))
cv2
.
circle
(
img
,
xy
,
int
(
13
*
esz
),
(
255
,
255
,
0
),
-
1
)
cv2
.
circle
(
bdcn
,
xy
,
int
(
13
*
esz
),
(
255
,
255
,
0
),
-
1
)
if
TRIANGLES
or
BODY_LINES
:
triangles
=
[
poseToTriangle
(
pose
)
for
pose
in
datum
.
poseKeypoints
]
for
triangle
in
triangles
:
if
triangle
is
not
None
:
if
TRIANGLES
:
cv2
.
drawContours
(
img
,
[
triangle
],
0
,
255
,
-
1
)
cv2
.
drawContours
(
bdcn
,
[
triangle
],
0
,
255
,
-
1
)
if
BODY_LINES
:
linePoints
=
triangleToBodyLine
(
triangle
)
cv2
.
line
(
img
,
trp
(
linePoints
[
0
]),
trp
(
linePoints
[
1
]),
(
0
,
255
,
0
),
int
(
6
*
esz
))
cv2
.
line
(
bdcn
,
trp
(
linePoints
[
0
]),
trp
(
linePoints
[
1
]),
(
0
,
255
,
0
),
int
(
6
*
esz
))
cv2
.
circle
(
output_canvas
,
xy
,
int
(
13
*
esz
),
(
255
,
255
,
0
),
-
1
)
if
BISEC_VECTORS
:
bisecVectors
=
[
poseToBisectVector
(
pose
,
CORRECTION_ANGLE
)
for
pose
in
datum
.
poseKeypoints
]
for
bisecVector
in
bisecVectors
:
if
bisecVector
is
not
None
:
cv2
.
arrowedLine
(
img
,
trp
(
bisecVector
[
1
]),
trp
(
bisecVector
[
0
]),
(
0
,
0
,
255
),
int
(
4
*
esz
))
cv2
.
arrowedLine
(
bdcn
,
trp
(
bisecVector
[
1
]),
trp
(
bisecVector
[
0
]),
(
0
,
0
,
255
),
int
(
4
*
esz
))
cv2
.
arrowedLine
(
output_canvas
,
trp
(
bisecVector
[
1
]),
trp
(
bisecVector
[
0
]),
(
0
,
0
,
255
),
int
(
4
*
esz
))
if
SAVE_FILE
:
cv2
.
imwrite
(
os
.
path
.
basename
(
img_name
),
img
)
if
BDCN_EDGES
:
cv2
.
imwrite
(
'CANVAS_'
+
os
.
path
.
basename
(
img_
bdcn
),
bdcn
)
cv2
.
imwrite
(
'CANVAS_'
+
os
.
path
.
basename
(
img_
output_canvas
),
output_canvas
)
if
SHOW_WINDOW
:
cv2
.
namedWindow
(
img_name
,
cv2
.
WINDOW_NORMAL
)
cv2
.
imshow
(
img_name
,
img
)
if
BDCN_EDGES
:
cv2
.
namedWindow
(
img_bdcn
,
cv2
.
WINDOW_NORMAL
)
cv2
.
imshow
(
img_bdcn
,
bdcn
)
cv2
.
waitKey
(
0
)
cv2
.
imshow
(
img_bdcn
,
output_canvas
)
#
cv2.waitKey(0)
if
SHOW_WINDOW
:
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
\ No newline at end of file
lib/bisection.py
View file @
c9206758
...
...
@@ -48,15 +48,15 @@ def getGlobalLineAngle(poses, CORRECTION_ANGLE):
def
getBisecPoint
(
a
,
b
,
c
,
CORRECTION_ANGLE
):
angle
=
getAngleGroundNormed
(
a
,
b
,
c
,
CORRECTION_ANGLE
)
dist
=
la
.
norm
(
a
-
b
)
dist
=
la
.
norm
(
a
-
b
)
*
2
d
=
(
int
(
dist
*
np
.
cos
(
angle
)),
int
(
dist
*
np
.
sin
(
angle
)))
#with origin zero
out
=
(
b
[
0
]
+
d
[
0
],
b
[
1
]
-
d
[
1
])
return
out
#with origin b
def
getBisecCone
(
a
,
b
,
c
,
length
,
width
,
CORRECTION_ANGLE
):
def
getBisecCone
(
a
,
b
,
c
,
length
,
BISEC_CONE_ANGLE
,
CORRECTION_ANGLE
):
angle
=
getAngleGroundNormed
(
a
,
b
,
c
,
CORRECTION_ANGLE
)
conePoint1
=
(
int
(
length
*
np
.
cos
(
angle
-
(
width
/
2
))),
int
(
length
*
np
.
sin
(
angle
-
(
width
/
2
))))
#with origin zero
conePoint2
=
(
int
(
length
*
np
.
cos
(
angle
+
(
width
/
2
))),
int
(
length
*
np
.
sin
(
angle
+
(
width
/
2
))))
#with origin zero
conePoint1
=
(
int
(
length
*
np
.
cos
(
angle
-
(
BISEC_CONE_ANGLE
/
2
))),
int
(
length
*
np
.
sin
(
angle
-
(
BISEC_CONE_ANGLE
/
2
))))
#with origin zero
conePoint2
=
(
int
(
length
*
np
.
cos
(
angle
+
(
BISEC_CONE_ANGLE
/
2
))),
int
(
length
*
np
.
sin
(
angle
+
(
BISEC_CONE_ANGLE
/
2
))))
#with origin zero
return
((
b
[
0
]
+
conePoint1
[
0
],
b
[
1
]
-
conePoint1
[
1
]),(
b
[
0
]
+
conePoint2
[
0
],
b
[
1
]
-
conePoint2
[
1
]))
def
poseToBisectVector
(
pose
,
CORRECTION_ANGLE
):
...
...
lib/triangles.py
View file @
c9206758
import
numpy
as
np
triangleTopSortedIndices
=
[
1
,
0
,
2
,
5
,
15
,
16
,
17
,
18
]
triangleLeftSortedIndices
=
[
11
,
24
,
13
,
22
,
10
,
9
]
triangleRightSortedIndices
=
[
14
,
21
,
19
,
20
,
13
,
12
]
def
reduceToTrianglePoint
(
indices
,
pose
):
points
=
pose
[
indices
]
#filter out poses wich are not part of the points points indices
if
len
(
points
)
<=
0
:
return
None
#no relevant indices exist
pointsFiltered
=
points
[
np
.
where
(
points
[:,
2
]
>
0.1
)[
0
]]
#filter out points bellow openpose confidence value of 0.
5
pointsFiltered
=
points
[
np
.
where
(
points
[:,
2
]
>
0.1
)[
0
]]
#filter out points bellow openpose confidence value of 0.
1
if
len
(
pointsFiltered
)
<=
0
or
pointsFiltered
is
None
:
bestPoint
=
points
[
np
.
argsort
(
points
[:,
2
])[::
-
1
]][
0
]
#points with best openpose confidence
if
bestPoint
[
2
]
>
0.0
:
...
...
@@ -19,6 +16,9 @@ def reduceToTrianglePoint(indices,pose):
return
pointsFiltered
[
0
]
#take first point if filterd has values
def
poseToTriangle
(
pose
):
triangleTopSortedIndices
=
[
1
,
0
,
2
,
5
,
15
,
16
,
17
,
18
]
triangleLeftSortedIndices
=
[
11
,
24
,
13
,
22
,
10
,
9
]
triangleRightSortedIndices
=
[
14
,
21
,
19
,
20
,
13
,
12
]
top
=
reduceToTrianglePoint
(
triangleTopSortedIndices
,
pose
)
left
=
reduceToTrianglePoint
(
triangleLeftSortedIndices
,
pose
)
right
=
reduceToTrianglePoint
(
triangleRightSortedIndices
,
pose
)
...
...
playground/basic_cv2_kmeans.py
View file @
c9206758
...
...
@@ -3,9 +3,12 @@ import cv2
import
os
IN_DIR
=
"../images/images_imdahl/"
# IN_DIR = "../images/images_imdahl/"
IN_DIR
=
"../images/out/fuse_1_bsds500/"
DISPLAY_RASTER_ELEMENTS
=
500
images
=
[
os
.
path
.
join
(
os
.
getcwd
(),
IN_DIR
,
f
)
for
f
in
os
.
listdir
(
IN_DIR
)]
os
.
chdir
(
'../images/out/images_imdahl/filter
ed_median/
'
)
#save images in this dir
os
.
chdir
(
'../images/out/images_imdahl/
bdcn_
filter
ing/test1
'
)
#save images in this dir
for
img_name
in
images
:
# img_name=images[0]
print
(
img_name
)
...
...
@@ -13,19 +16,47 @@ for img_name in images:
# cv2.imshow('res2'+img_name,img)
# cv2.waitKey(0)
# image = cv2.imread('../images/out/fuse_1_bsds500/0.png')
max_lw
=
max
(
len
(
img
),
len
(
img
[
0
]))
esz
=
max_lw
/
DISPLAY_RASTER_ELEMENTS
print
(
"max_lw,esz"
,
max_lw
,
esz
)
# img = cv2.bitwise_not(img)
cv2
.
imshow
(
'res2'
+
img_name
,
img
)
blurred
=
cv2
.
medianBlur
(
img
,
int
(
esz
*
5
)
+
1
if
int
(
esz
*
5
)
%
2
==
0
else
int
(
esz
*
5
))
print
(
"med1"
)
cv2
.
waitKey
(
0
)
cv2
.
imshow
(
'res2'
+
img_name
,
blurred
)
blurred
=
cv2
.
bilateralFilter
(
blurred
,
30
,
60
,
60
)
print
(
"bil1"
)
cv2
.
waitKey
(
0
)
cv2
.
imshow
(
'res2'
+
img_name
,
blurred
)
blurred
=
cv2
.
bilateralFilter
(
blurred
,
30
,
60
,
60
)
print
(
"bil2"
)
cv2
.
waitKey
(
0
)
cv2
.
imshow
(
'res2'
+
img_name
,
blurred
)
blurred
=
cv2
.
bilateralFilter
(
blurred
,
30
,
60
,
60
)
print
(
"bil3"
)
cv2
.
waitKey
(
0
)
cv2
.
imshow
(
'res2'
+
img_name
,
blurred
)
blurred
=
cv2
.
bilateralFilter
(
blurred
,
30
,
60
,
60
)
print
(
"bil4"
)
cv2
.
waitKey
(
0
)
cv2
.
imshow
(
'res2'
+
img_name
,
blurred
)
#applying filters
bil
=
cv2
.
bilateralFilter
(
img
,
50
,
30
,
30
)
# cv2.imshow('res2'+img_name,bil)
# cv2.waitKey(0)
#applying filters
bil
=
cv2
.
bilateralFilter
(
bil
,
15
,
60
,
60
)
# cv2.imshow('res2'+img_name,bil)
# cv2.waitKey(0)
#applying filters
median
=
cv2
.
medianBlur
(
bil
,
5
)
# cv2.imshow('res2'+img_name,median)
# cv2.waitKey(0)
median
=
cv2
.
medianBlur
(
median
,
5
)
#
bil = cv2.bilateralFilter(img,50,30,30)
#
#
cv2.imshow('res2'+img_name,bil)
#
#
cv2.waitKey(0)
#
#applying filters
#
bil = cv2.bilateralFilter(bil,15,60,60)
#
#
cv2.imshow('res2'+img_name,bil)
#
#
cv2.waitKey(0)
#
#applying filters
#
median = cv2.medianBlur(bil,5)
#
#
cv2.imshow('res2'+img_name,median)
#
#
cv2.waitKey(0)
#
median = cv2.medianBlur(median,5)
# cv2.imshow('res2'+img_name,median)
# cv2.waitKey(0)
...
...
@@ -44,9 +75,10 @@ for img_name in images:
# res = center[label.flatten()]
# res2 = res.reshape((img.shape))
cv2
.
imwrite
(
os
.
path
.
basename
(
img_name
),
median
)
# cv2.imshow('res2'+img_name,res2)
# cv2.waitKey(0)
cv2
.
imwrite
(
os
.
path
.
basename
(
img_name
)
+
"_med5esz_30_60_60.png"
,
blurred
)
cv2
.
imshow
(
'res2'
+
img_name
,
blurred
)
cv2
.
waitKey
(
0
)
#cv2.imwrite('/Users/Tilman/Documents/Programme/Python/forschungspraktikum/images/out/images_imdahl/kmean/'+img_name,res2)
# cv2.waitKey(0)
cv2
.
destroyAllWindows
()
\ No newline at end of file
playground/threshold_slider.py
View file @
c9206758
...
...
@@ -64,12 +64,26 @@ def on_gauss(val):
gauss
=
val
update
()
DISPLAY_RASTER_ELEMENTS
=
500
def
update
():
image
=
cv
.
imread
(
'../images/out/fuse_1_bsds500/1.png'
)
image
=
cv
.
bitwise_not
(
image
)
blurred
=
cv
.
bilateralFilter
(
image
,
50
,
100
,
100
)
blurred
=
cv
.
medianBlur
(
blurred
,
gauss
)
blurred
=
cv
.
GaussianBlur
(
blurred
,
(
gauss
,
gauss
),
0
)
image
=
cv
.
imread
(
'../images/out/fuse_1_bsds500/0.png'
)
max_lw
=
max
(
len
(
image
),
len
(
image
[
0
]))
esz
=
max_lw
/
DISPLAY_RASTER_ELEMENTS
# image = cv.bitwise_not(image)
blurred
=
cv
.
medianBlur
(
image
,
int
(
int
(
10
*
esz
)
/
2
))
#blurred = cv.bilateralFilter(blurred,int(70*esz),int(120*esz),int(120*esz))
if
(
gauss
>
10
):
blurred
=
cv
.
bilateralFilter
(
blurred
,
int
(
70
*
esz
),
int
(
120
*
esz
),
int
(
120
*
esz
))
if
(
gauss
>
20
):
blurred
=
cv
.
bilateralFilter
(
blurred
,
int
(
70
*
esz
),
int
(
120
*
esz
),
int
(
120
*
esz
))
if
(
gauss
>
30
):
blurred
=
cv
.
bilateralFilter
(
blurred
,
int
(
70
*
esz
),
int
(
120
*
esz
),
int
(
120
*
esz
))
if
(
gauss
>
40
):
blurred
=
cv
.
bilateralFilter
(
blurred
,
int
(
70
*
esz
),
int
(
120
*
esz
),
int
(
120
*
esz
))
# blurred = cv.medianBlur(image,gauss)
# blurred = cv.GaussianBlur(blurred, (gauss, gauss), 0)
gray
=
cv
.
cvtColor
(
blurred
,
cv
.
COLOR_BGR2GRAY
)
# auto = auto_canny(blurred)
...
...
@@ -83,20 +97,20 @@ def update():
# else:
# print("dont show")
# cv.imshow("Original", blurred)
print
(
rho
,
np
.
pi
/
theta
,
threshold
)
lines
=
cv
.
HoughLines
(
gray
,
rho
,
np
.
pi
/
theta
,
threshold
)
if
lines
is
not
None
:
for
rho2
,
theta2
in
lines
[:,
0
]:
a
=
np
.
cos
(
theta2
)
b
=
np
.
sin
(
theta2
)
x0
=
a
*
rho2
y0
=
b
*
rho2
x1
=
int
(
x0
+
1000
*
(
-
b
))
y1
=
int
(
y0
+
1000
*
(
a
))
x2
=
int
(
x0
-
1000
*
(
-
b
))
y2
=
int
(
y0
-
1000
*
(
a
))
cv
.
line
(
blurred
,(
x1
,
y1
),(
x2
,
y2
),(
0
,
0
,
255
),
2
)
#
print(rho,np.pi/theta,threshold)
#
lines = cv.HoughLines(gray,rho,np.pi/theta,threshold)
#
if lines is not None:
#
for rho2,theta2 in lines[:,0]:
#
a = np.cos(theta2)
#
b = np.sin(theta2)
#
x0 = a*rho2
#
y0 = b*rho2
#
x1 = int(x0 + 1000*(-b))
#
y1 = int(y0 + 1000*(a))
#
x2 = int(x0 - 1000*(-b))
#
y2 = int(y0 - 1000*(a))
#
cv.line(blurred,(x1,y1),(x2,y2),(0,0,255),2)
cv
.
imshow
(
"Original"
,
blurred
)
...
...
@@ -107,7 +121,7 @@ cv.createTrackbar("theta", "Original" , 0, 360, on_theta)
cv
.
createTrackbar
(
"threshold"
,
"Original"
,
0
,
9000
,
on_threshold
)
cv
.
createTrackbar
(
"minline"
,
"Original"
,
0
,
500
,
on_minline
)
cv
.
createTrackbar
(
"maxgap"
,
"Original"
,
0
,
100
,
on_maxgap
)
cv
.
createTrackbar
(
"gauss"
,
"Original"
,
0
,
1
00
,
on_gauss
)
cv
.
createTrackbar
(
"gauss"
,
"Original"
,
0
,
5
00
,
on_gauss
)
update
()
cv
.
waitKey
(
0
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment