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
e8cfa982
Unverified
Commit
e8cfa982
authored
Dec 25, 2019
by
tilman
Browse files
inbetween commit
parent
4eccdaaa
Changes
4
Hide whitespace changes
Inline
Side-by-side
conesTest.py
deleted
100644 → 0
View file @
4eccdaaa
from
shapely.geometry
import
Polygon
import
numpy
as
np
import
itertools
import
cv2
from
lib.bisection
import
*
def
overlay_two_image_v2
(
image
,
overlay
,
ignore_color
=
[
0
,
0
,
0
]):
ignore_color
=
np
.
asarray
(
ignore_color
)
mask
=
(
overlay
==
ignore_color
).
all
(
-
1
,
keepdims
=
True
)
out
=
np
.
where
(
mask
,
image
,(
image
*
0.2
+
overlay
*
0.2
).
astype
(
image
.
dtype
))
return
out
bisecCones
=
np
.
array
([
Polygon
([[
-
719
,
1205
],
[
-
952
,
207
],
[
536
,
386
],
[
-
719
,
1205
]]),
Polygon
([[
-
554
,
1264
],
[
-
824
,
275
],
[
669
,
397
],
[
-
554
,
1264
]]),
Polygon
([[
-
371
,
1444
],
[
-
738
,
486
],
[
760
,
460
],
[
-
371
,
1444
]]),
Polygon
([[
1473
,
1200
],
[
653
,
1818
],
[
215
,
384
],
[
1473
,
1200
]])
])
img_name
=
"/Users/Tilman/Documents/Programme/Python/forschungspraktikum/art-structures-env/src/images/images_imdahl/Judas_und_Christus.jpg"
img
=
cv2
.
imread
(
img_name
)
orig
=
img
.
copy
()
def
overlay_two_image_v2
(
image
,
overlay
,
ignore_color
=
[
0
,
0
,
0
]):
ignore_color
=
np
.
asarray
(
ignore_color
)
mask
=
(
overlay
==
ignore_color
).
all
(
-
1
,
keepdims
=
True
)
out
=
np
.
where
(
mask
,
image
,(
image
*
0.5
+
overlay
*
0.5
).
astype
(
image
.
dtype
))
return
out
intersections
=
coneIntersections
(
bisecCones
)
maxlevel
=
max
(
map
(
lambda
t
:
len
(
t
),
intersections
.
keys
()))
for
combi
in
intersections
:
#overlay = orig.copy()
is_not_last_level
=
len
(
combi
)
<
maxlevel
overlay
=
np
.
zeros
((
len
(
img
),
len
(
img
[
0
]),
3
),
np
.
uint8
)
color
=
min
(((
len
(
combi
)
-
2
)
*
150
,
255
))
cv2
.
drawContours
(
overlay
,
[
polyToArr
(
intersections
[
combi
])],
0
,
(
color
,
0
,
255
),
-
1
)
if
not
is_not_last_level
:
#draw centroid of last polygon
xy
=
(
int
(
intersections
[
combi
].
centroid
.
x
),
int
(
intersections
[
combi
].
centroid
.
y
))
cv2
.
circle
(
overlay
,
xy
,
10
,
(
0
,
255
,
0
),
-
1
)
img
=
overlay_two_image_v2
(
img
,
overlay
,
[
0
,
0
,
0
])
cv2
.
namedWindow
(
img_name
,
cv2
.
WINDOW_NORMAL
)
cv2
.
imshow
(
img_name
,
img
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
\ No newline at end of file
detect_structures.py
View file @
e8cfa982
...
...
@@ -60,7 +60,7 @@ for img_name in images:
img
=
datum
.
cvOutputData
#overlay = img.copy()
#
print("poses:"+str(
len(
datum.poseKeypoints))
)
print
(
"poses:"
+
str
(
datum
.
poseKeypoints
))
if
TRIANGLES
:
triangles
=
[
poseToTriangle
(
pose
)
for
pose
in
datum
.
poseKeypoints
]
for
triangle
in
triangles
:
...
...
lib/bisection.py
View file @
e8cfa982
...
...
@@ -9,20 +9,20 @@ def polyToArr(poly):
else
:
return
None
def
getAngle
(
a
,
b
,
c
,
CORRECTION_ANGLE
):
def
getAngle
(
a
,
b
,
c
,
CORRECTION_ANGLE
):
#checked is correct
ba
=
a
-
b
bc
=
c
-
b
cosine_angle
=
np
.
dot
(
ba
,
bc
)
/
(
np
.
linalg
.
norm
(
ba
)
*
np
.
linalg
.
norm
(
bc
))
angle
=
np
.
arccos
(
cosine_angle
)
print
(
"angle"
,
angle
,
np
.
rad2deg
(
angle
),
360
-
np
.
rad2deg
(
angle
),
180
-
np
.
rad2deg
(
angle
))
#
print("angle",angle,np.rad2deg(angle),360-np.rad2deg(angle),180-np.rad2deg(angle))
# TODO get the angle right....
# angle = angle - np.deg2rad(CORRECTION_ANGLE)
if
(
a
[
0
]
-
b
[
0
]
<
0
):
#check wich direction (left/right) the vector should point
print
(
"left angle"
,
angle
,
np
.
rad2deg
(
angle
))
angle
=
360
-
angle
#- np.deg2rad(CORRECTION_ANGLE)
else
:
print
(
"right angle"
,
angle
,
np
.
rad2deg
(
angle
))
angle
=
180
-
angle
#+ np.deg2rad(CORRECTION_ANGLE)
#
if(a[0]-b[0]<0): #check wich direction (left/right) the vector should point
#
print("left angle",angle,np.rad2deg(angle))
#
angle = 360 - angle #- np.deg2rad(CORRECTION_ANGLE)
#
else:
#
print("right angle",angle,np.rad2deg(angle))
#
angle = 180 - angle #+ np.deg2rad(CORRECTION_ANGLE)
return
angle
def
getGlobalLineAngle
(
poses
,
CORRECTION_ANGLE
):
...
...
@@ -30,7 +30,9 @@ def getGlobalLineAngle(poses, CORRECTION_ANGLE):
def
getBisecPoint
(
a
,
b
,
c
,
CORRECTION_ANGLE
):
angle
=
getAngle
(
a
,
b
,
c
,
CORRECTION_ANGLE
)
print
(
"getBisecPoint-getAngle full"
,
angle
,
np
.
rad2deg
(
angle
))
angle
=
angle
/
2
print
(
"getBisecPoint-getAngle half"
,
angle
,
np
.
rad2deg
(
angle
))
dist
=
la
.
norm
(
a
-
b
)
# dist = 100
d
=
(
int
(
dist
*
np
.
cos
(
angle
)),
int
(
dist
*
np
.
sin
(
angle
)))
#with origin zero
...
...
playground/basic_bisection_vector_test.py
View file @
e8cfa982
...
...
@@ -7,6 +7,8 @@ from shapely.geometry import Polygon
from
lib.bisection
import
*
CORRECTION_ANGLE
=
20
def
trp
(
point
):
#trimPoint
return
(
int
(
point
[
0
]),
int
(
point
[
1
]))
...
...
@@ -37,11 +39,11 @@ dist1 = la.norm(a-b)
dist2
=
la
.
norm
(
b
-
c
)
print
(
"distance"
,
dist1
,
dist2
)
angle
=
getAngle
(
a
,
b
,
c
)
angle
=
getAngle
(
a
,
b
,
c
,
CORRECTION_ANGLE
)
print
(
np
.
degrees
(
angle
))
#degress
print
(
angle
)
#radians
#pd = getBisecPoint(a,b,c)
pd1
,
pd2
=
getBisecCone
(
a
,
b
,
c
,
np
.
deg2rad
(
30
))
pd1
,
pd2
=
getBisecCone
(
a
,
b
,
c
,
np
.
deg2rad
(
30
)
,
CORRECTION_ANGLE
)
#cone = np.array([pd1, pd2, b])
conePoly
=
Polygon
([
pd1
,
pd2
,
b
])
...
...
@@ -54,11 +56,11 @@ cv2.line(img, pa, pb, (0,255,0));
cv2
.
line
(
img
,
pb
,
pc
,
(
0
,
255
,
0
));
cv2
.
line
(
img
,
pb
,
pd1
,
(
0
,
0
,
255
));
cv2
.
line
(
img
,
pb
,
pd2
,
(
0
,
0
,
255
));
print
(
len
(
img
))
print
(
len
(
img
[
0
]))
mainCanvas
=
Polygon
(((
0
,
len
(
img
)),
(
0
,
0
),
(
len
(
img
[
0
]),
0
),
(
len
(
img
[
0
]),
len
(
img
))))
cv2
.
drawContours
(
img
,
[
polyToArr
(
conePoly
)],
0
,
255
,
-
1
)
cv2
.
drawContours
(
img
,
[
polyToArr
(
mainCanvas
)],
0
,
255
,
-
1
)
#
print(len(img))
#
print(len(img[0]))
#
mainCanvas = Polygon(((0,len(img)), (0,0), (len(img[0]),0), (len(img[0]),len(img))))
#
cv2.drawContours(img, [polyToArr(conePoly)], 0, 255, -1)
#
cv2.drawContours(img, [polyToArr(mainCanvas)], 0, 255, -1)
cv2
.
imshow
(
"test"
,
img
)
...
...
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