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
33d868b1
Unverified
Commit
33d868b1
authored
Dec 29, 2019
by
tilman
Browse files
add bdcn res to detect structures
parent
347ab429
Changes
3
Hide whitespace changes
Inline
Side-by-side
detect_structures.py
View file @
33d868b1
...
...
@@ -27,6 +27,7 @@ DISPLAY_RASTER_ELEMENTS = 500
OUT_DIR
=
'images/out/images_imdahl/main_structure_global_line'
#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
=
False
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
]]
...
...
@@ -58,9 +59,13 @@ if not SKIP_OPENPOSE:
opWrapper
.
start
()
images
=
[
os
.
path
.
join
(
os
.
getcwd
(),
IN_DIR
,
f
)
for
f
in
os
.
listdir
(
IN_DIR
)]
#make path absolute so os.chdir has no side effects
images_bdcn
=
[
os
.
path
.
join
(
os
.
getcwd
(),
IN_DIR_BDCN
,
f
)
for
f
in
os
.
listdir
(
IN_DIR_BDCN
)]
images
.
sort
()
images_bdcn
.
sort
()
os
.
chdir
(
OUT_DIR
)
#save images in this dir
for
img_name
in
images
:
#for img_name in images:
for
img_name
,
img_bdcn
in
list
(
zip
(
images
,
images_bdcn
)):
# Process Image
print
(
"calculating: "
+
img_name
)
img
=
cv2
.
imread
(
img_name
)
...
...
playground/bdcn_postprocessing.py
View file @
33d868b1
...
...
@@ -46,15 +46,15 @@ datum.poseKeypoints = OPENPOSE_DEMO_KEYPOINTS
# opWrapper.configure(params)
# opWrapper.start()
for
img_name
,
img_bdcn
in
list
(
zip
(
images
,
images_bdcn
)):
#christus only
for
img_name
,
img_bdcn
in
list
(
zip
(
images
,
images_bdcn
))
[
15
:
16
]
:
#christus only
img
=
cv2
.
imread
(
img_name
)
bdcn
=
cv2
.
imread
(
img_bdcn
)
max_lw
=
max
(
len
(
img
),
len
(
img
[
0
]))
esz
=
max_lw
/
DISPLAY_RASTER_ELEMENTS
datum
=
op
.
Datum
()
datum
.
cvInputData
=
img
opWrapper
.
emplaceAndPop
([
datum
])
#
datum = op.Datum()
#
datum.cvInputData = img
#
opWrapper.emplaceAndPop([datum])
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
...
...
@@ -75,29 +75,31 @@ for img_name, img_bdcn in list(zip(images, images_bdcn)): #christus only
cv2
.
namedWindow
(
img_name
,
cv2
.
WINDOW_NORMAL
)
cv2
.
namedWindow
(
img_name
+
'bdcn'
,
cv2
.
WINDOW_NORMAL
)
cv2
.
namedWindow
(
img_name
+
'blurred'
,
cv2
.
WINDOW_NORMAL
)
#
cv2.namedWindow(img_name+'blurred', cv2.WINDOW_NORMAL)
rho
=
10
theta
=
18
0
rho
=
3
theta
=
36
0
threshold
=
2950
minline
=
int
(
max_lw
/
4
)
#minline 1/6 of image width/heigth
maxgap
=
int
(
max_lw
/
5
0
)
#minline 1/12 of image width/heigth
minline
=
int
(
max_lw
/
2
)
#minline 1/6 of image width/heigth
maxgap
=
int
(
max_lw
/
10
0
)
#minline 1/12 of image width/heigth
print
(
"params"
,
rho
,
theta
,
threshold
,
minline
,
maxgap
)
#blurred = bdcn.copy()
#cv2.imshow(img_name+'blurred', blurred)
gray
=
cv2
.
cvtColor
(
bdcn
,
cv2
.
COLOR_BGR2GRAY
)
blurred
=
cv2
.
GaussianBlur
(
gray
,(
5
,
5
),
0
)
blurred
=
cv2
.
GaussianBlur
(
gray
,(
1
,
1
),
0
)
# cv2.imshow(img_name+'blurred', blurred)
# cv2.waitKey(0)
lines
=
cv2
.
HoughLinesP
(
image
=
blurred
,
rho
=
rho
,
theta
=
np
.
pi
/
theta
,
threshold
=
threshold
,
minLineLength
=
minline
,
maxLineGap
=
maxgap
)
lines
=
cv2
.
HoughLines
(
image
=
blurred
,
rho
=
rho
,
theta
=
np
.
pi
/
theta
,
threshold
=
threshold
,
minLineLength
=
minline
,
maxLineGap
=
maxgap
)
# if(lines):
if
lines
is
not
None
:
print
(
"len"
,
len
(
lines
))
for
line
in
lines
:
x1
,
y1
,
x2
,
y2
=
line
[
0
]
cv2
.
line
(
bdcn
,
(
x1
,
y1
),
(
x2
,
y2
),
(
255
,
0
,
0
),
3
)
cv2
.
imshow
(
img_name
,
img
)
cv2
.
imshow
(
img_name
+
'blurred'
,
blurred
)
#
cv2.imshow(img_name+'blurred', blurred)
cv2
.
imshow
(
img_name
+
'bdcn'
,
bdcn
)
cv2
.
waitKey
(
0
)
...
...
playground/threshold_slider.py
View file @
33d868b1
...
...
@@ -31,47 +31,83 @@ theta=4
threshold
=
100
minline
=
220
maxgap
=
30
gauss
=
11
def
on_rho
(
val
):
if
(
val
<=
0
):
return
global
rho
rho
=
val
update
()
def
on_theta
(
val
):
if
(
val
<=
0
):
return
global
theta
theta
=
val
update
()
def
on_threshold
(
val
):
if
(
val
<=
0
):
return
global
threshold
threshold
=
val
update
()
def
on_minline
(
val
):
if
(
val
<=
0
):
return
global
minline
minline
=
val
update
()
def
on_maxgap
(
val
):
if
(
val
<=
0
):
return
global
maxgap
maxgap
=
val
update
()
def
on_gauss
(
val
):
if
(
val
<=
0
):
return
global
gauss
gauss
=
val
update
()
def
update
():
image
=
cv
.
imread
(
'../images/out/fuse_1_bsds500/1.png'
)
lines
=
cv
.
HoughLinesP
(
image
=
image
,
rho
=
rho
,
theta
=
np
.
pi
/
theta
,
threshold
=
threshold
,
minLineLength
=
minline
,
maxLineGap
=
maxgap
)
image
=
cv
.
bitwise_not
(
image
)
blurred
=
cv
.
bilateralFilter
(
image
,
50
,
100
,
100
)
blurred
=
cv
.
medianBlur
(
blurred
,
gauss
)
blurred
=
cv
.
GaussianBlur
(
blurred
,
(
gauss
,
gauss
),
0
)
gray
=
cv
.
cvtColor
(
blurred
,
cv
.
COLOR_BGR2GRAY
)
# auto = auto_canny(blurred)
# lines = cv.HoughLinesP(image=gray, rho=rho, theta=np.pi/theta, threshold=threshold, minLineLength=minline, maxLineGap=maxgap)
# if(lines):
# if lines is not None:
# for line in lines:
# x1, y1, x2, y2 = line[0]
# cv.line(blurred, (x1, y1), (x2, y2), (255, 0, 0), 3)
# cv.imshow("Original", blurred)
# 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
line
in
lines
:
x1
,
y1
,
x2
,
y2
=
line
[
0
]
cv
.
line
(
image
,
(
x1
,
y1
),
(
x2
,
y2
),
(
255
,
0
,
0
),
3
)
cv
.
imshow
(
"Original"
,
image
)
else
:
print
(
"dont show"
)
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
)
cv
.
namedWindow
(
"Original"
,
cv
.
WINDOW_NORMAL
)
cv
.
createTrackbar
(
"rho"
,
"Original"
,
0
,
50
,
on_rho
)
cv
.
createTrackbar
(
"theta"
,
"Original"
,
0
,
360
,
on_theta
)
cv
.
createTrackbar
(
"threshold"
,
"Original"
,
0
,
5
00
,
on_threshold
)
cv
.
createTrackbar
(
"threshold"
,
"Original"
,
0
,
90
00
,
on_threshold
)
cv
.
createTrackbar
(
"minline"
,
"Original"
,
0
,
500
,
on_minline
)
cv
.
createTrackbar
(
"maxgap"
,
"Original"
,
0
,
100
,
on_maxgap
)
cv
.
createTrackbar
(
"gauss"
,
"Original"
,
0
,
100
,
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