Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Art Structures - LME Praktikum
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tilman Marquart
Art Structures - LME Praktikum
Commits
e8cfa982
Unverified
Commit
e8cfa982
authored
Dec 25, 2019
by
tilman
Browse files
Options
Downloads
Patches
Plain Diff
inbetween commit
parent
4eccdaaa
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
conesTest.py
+0
-59
0 additions, 59 deletions
conesTest.py
detect_structures.py
+1
-1
1 addition, 1 deletion
detect_structures.py
lib/bisection.py
+10
-8
10 additions, 8 deletions
lib/bisection.py
playground/basic_bisection_vector_test.py
+9
-7
9 additions, 7 deletions
playground/basic_bisection_vector_test.py
with
20 additions
and
75 deletions
conesTest.py
deleted
100644 → 0
+
0
−
59
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
This diff is collapsed.
Click to expand it.
detect_structures.py
+
1
−
1
View file @
e8cfa982
...
@@ -60,7 +60,7 @@ for img_name in images:
...
@@ -60,7 +60,7 @@ for img_name in images:
img
=
datum
.
cvOutputData
img
=
datum
.
cvOutputData
#overlay = img.copy()
#overlay = img.copy()
#
print("poses:"+str(
len(
datum.poseKeypoints))
)
print
(
"
poses:
"
+
str
(
datum
.
poseKeypoints
))
if
TRIANGLES
:
if
TRIANGLES
:
triangles
=
[
poseToTriangle
(
pose
)
for
pose
in
datum
.
poseKeypoints
]
triangles
=
[
poseToTriangle
(
pose
)
for
pose
in
datum
.
poseKeypoints
]
for
triangle
in
triangles
:
for
triangle
in
triangles
:
...
...
This diff is collapsed.
Click to expand it.
lib/bisection.py
+
10
−
8
View file @
e8cfa982
...
@@ -9,20 +9,20 @@ def polyToArr(poly):
...
@@ -9,20 +9,20 @@ def polyToArr(poly):
else
:
else
:
return
None
return
None
def
getAngle
(
a
,
b
,
c
,
CORRECTION_ANGLE
):
def
getAngle
(
a
,
b
,
c
,
CORRECTION_ANGLE
):
#checked is correct
ba
=
a
-
b
ba
=
a
-
b
bc
=
c
-
b
bc
=
c
-
b
cosine_angle
=
np
.
dot
(
ba
,
bc
)
/
(
np
.
linalg
.
norm
(
ba
)
*
np
.
linalg
.
norm
(
bc
))
cosine_angle
=
np
.
dot
(
ba
,
bc
)
/
(
np
.
linalg
.
norm
(
ba
)
*
np
.
linalg
.
norm
(
bc
))
angle
=
np
.
arccos
(
cosine_angle
)
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....
# TODO get the angle right....
# angle = angle - np.deg2rad(CORRECTION_ANGLE)
# angle = angle - np.deg2rad(CORRECTION_ANGLE)
if
(
a
[
0
]
-
b
[
0
]
<
0
):
#check wich direction (left/right) the vector should point
#
if(a[0]-b[0]<0): #check wich direction (left/right) the vector should point
print
(
"
left angle
"
,
angle
,
np
.
rad2deg
(
angle
))
#
print("left angle",angle,np.rad2deg(angle))
angle
=
360
-
angle
#- np.deg2rad(CORRECTION_ANGLE)
#
angle = 360 - angle #- np.deg2rad(CORRECTION_ANGLE)
else
:
#
else:
print
(
"
right angle
"
,
angle
,
np
.
rad2deg
(
angle
))
#
print("right angle",angle,np.rad2deg(angle))
angle
=
180
-
angle
#+ np.deg2rad(CORRECTION_ANGLE)
#
angle = 180 - angle #+ np.deg2rad(CORRECTION_ANGLE)
return
angle
return
angle
def
getGlobalLineAngle
(
poses
,
CORRECTION_ANGLE
):
def
getGlobalLineAngle
(
poses
,
CORRECTION_ANGLE
):
...
@@ -30,7 +30,9 @@ def getGlobalLineAngle(poses, CORRECTION_ANGLE):
...
@@ -30,7 +30,9 @@ def getGlobalLineAngle(poses, CORRECTION_ANGLE):
def
getBisecPoint
(
a
,
b
,
c
,
CORRECTION_ANGLE
):
def
getBisecPoint
(
a
,
b
,
c
,
CORRECTION_ANGLE
):
angle
=
getAngle
(
a
,
b
,
c
,
CORRECTION_ANGLE
)
angle
=
getAngle
(
a
,
b
,
c
,
CORRECTION_ANGLE
)
print
(
"
getBisecPoint-getAngle full
"
,
angle
,
np
.
rad2deg
(
angle
))
angle
=
angle
/
2
angle
=
angle
/
2
print
(
"
getBisecPoint-getAngle half
"
,
angle
,
np
.
rad2deg
(
angle
))
dist
=
la
.
norm
(
a
-
b
)
dist
=
la
.
norm
(
a
-
b
)
# dist = 100
# dist = 100
d
=
(
int
(
dist
*
np
.
cos
(
angle
)),
int
(
dist
*
np
.
sin
(
angle
)))
#with origin zero
d
=
(
int
(
dist
*
np
.
cos
(
angle
)),
int
(
dist
*
np
.
sin
(
angle
)))
#with origin zero
...
...
This diff is collapsed.
Click to expand it.
playground/basic_bisection_vector_test.py
+
9
−
7
View file @
e8cfa982
...
@@ -7,6 +7,8 @@ from shapely.geometry import Polygon
...
@@ -7,6 +7,8 @@ from shapely.geometry import Polygon
from
lib.bisection
import
*
from
lib.bisection
import
*
CORRECTION_ANGLE
=
20
def
trp
(
point
):
#trimPoint
def
trp
(
point
):
#trimPoint
return
(
int
(
point
[
0
]),
int
(
point
[
1
]))
return
(
int
(
point
[
0
]),
int
(
point
[
1
]))
...
@@ -37,11 +39,11 @@ dist1 = la.norm(a-b)
...
@@ -37,11 +39,11 @@ dist1 = la.norm(a-b)
dist2
=
la
.
norm
(
b
-
c
)
dist2
=
la
.
norm
(
b
-
c
)
print
(
"
distance
"
,
dist1
,
dist2
)
print
(
"
distance
"
,
dist1
,
dist2
)
angle
=
getAngle
(
a
,
b
,
c
)
angle
=
getAngle
(
a
,
b
,
c
,
CORRECTION_ANGLE
)
print
(
np
.
degrees
(
angle
))
#degress
print
(
np
.
degrees
(
angle
))
#degress
print
(
angle
)
#radians
print
(
angle
)
#radians
#pd = getBisecPoint(a,b,c)
#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])
#cone = np.array([pd1, pd2, b])
conePoly
=
Polygon
([
pd1
,
pd2
,
b
])
conePoly
=
Polygon
([
pd1
,
pd2
,
b
])
...
@@ -54,11 +56,11 @@ cv2.line(img, pa, pb, (0,255,0));
...
@@ -54,11 +56,11 @@ cv2.line(img, pa, pb, (0,255,0));
cv2
.
line
(
img
,
pb
,
pc
,
(
0
,
255
,
0
));
cv2
.
line
(
img
,
pb
,
pc
,
(
0
,
255
,
0
));
cv2
.
line
(
img
,
pb
,
pd1
,
(
0
,
0
,
255
));
cv2
.
line
(
img
,
pb
,
pd1
,
(
0
,
0
,
255
));
cv2
.
line
(
img
,
pb
,
pd2
,
(
0
,
0
,
255
));
cv2
.
line
(
img
,
pb
,
pd2
,
(
0
,
0
,
255
));
print
(
len
(
img
))
#
print(len(img))
print
(
len
(
img
[
0
]))
#
print(len(img[0]))
mainCanvas
=
Polygon
(((
0
,
len
(
img
)),
(
0
,
0
),
(
len
(
img
[
0
]),
0
),
(
len
(
img
[
0
]),
len
(
img
))))
#
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(conePoly)], 0, 255, -1)
cv2
.
drawContours
(
img
,
[
polyToArr
(
mainCanvas
)],
0
,
255
,
-
1
)
#
cv2.drawContours(img, [polyToArr(mainCanvas)], 0, 255, -1)
cv2
.
imshow
(
"
test
"
,
img
)
cv2
.
imshow
(
"
test
"
,
img
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment