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
961ab0b2
Unverified
Commit
961ab0b2
authored
Jan 05, 2020
by
tilman
Browse files
changed main script
parent
33d868b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
detect_structures.py
View file @
961ab0b2
...
...
@@ -6,17 +6,20 @@ import numpy as np
import
os
from
sys
import
platform
from
dotmap
import
DotMap
from
shapely
import
affinity
from
shapely.geometry
import
Polygon
#sys.path.append('/Users/Tilman/Documents/Programme/Python/forschungspraktikum/openpose/python');
from
openpose
import
pyopenpose
as
op
from
lib.triangles
import
*
from
lib.bisection
import
*
from
lib.misc
import
*
SHOW_WINDOW
=
Tru
e
SHOW_WINDOW
=
Fals
e
SAVE_FILE
=
not
SHOW_WINDOW
SAVE_BDCN
=
True
TRIANGLES
=
False
BODY_LINES
=
True
BISEC_VECTORS
=
Tru
e
BISEC_VECTORS
=
Fals
e
BISEC_CONES
=
True
GLOBAL_LINE
=
True
BISEC_CONE_ANGLE
=
50
...
...
@@ -24,7 +27,8 @@ CORRECTION_ANGLE = 23
OVERLAY_ALPHA
=
0.2
BISEC_SKIP_LOWER_LEVELS
=
True
DISPLAY_RASTER_ELEMENTS
=
500
OUT_DIR
=
'images/out/images_imdahl/main_structure_global_line'
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/"
...
...
@@ -69,6 +73,7 @@ for img_name, img_bdcn in list(zip(images, images_bdcn)):
# Process Image
print
(
"calculating: "
+
img_name
)
img
=
cv2
.
imread
(
img_name
)
bdcn
=
cv2
.
imread
(
img_bdcn
)
max_lw
=
max
(
len
(
img
),
len
(
img
[
0
]))
esz
=
max_lw
/
DISPLAY_RASTER_ELEMENTS
if
SKIP_OPENPOSE
:
...
...
@@ -79,7 +84,24 @@ for img_name, img_bdcn in list(zip(images, images_bdcn)):
datum
=
op
.
Datum
()
datum
.
cvInputData
=
img
opWrapper
.
emplaceAndPop
([
datum
])
# img = datum.cvOutputData
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
)
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
sconvexhull
=
affinity
.
scale
(
convexhull
,
xfact
=
1.6
,
yfact
=
1.6
,
origin
=
convexhull
.
centroid
)
# print(convexhull)
#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
)
#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
))
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
...
...
@@ -106,8 +128,11 @@ 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
(
img
,
xy
,
(
xy
[
0
]
+
d_l
[
0
],
xy
[
1
]
-
d_l
[
1
]),
(
0
,
255
,
255
),
int
(
10
*
esz
))
cv2
.
circle
(
img
,
xy
,
int
(
10
*
esz
),
(
255
,
255
,
0
),
-
1
)
cv2
.
line
(
bdcn
,
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
]
...
...
@@ -115,21 +140,29 @@ for img_name, img_bdcn in list(zip(images, images_bdcn)):
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
))
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
))
if
SAVE_FILE
:
cv2
.
imwrite
(
os
.
path
.
basename
(
img_name
),
img
)
if
BDCN_EDGES
:
cv2
.
imwrite
(
'CANVAS_'
+
os
.
path
.
basename
(
img_bdcn
),
bdcn
)
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
)
if
SHOW_WINDOW
:
cv2
.
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