threshold_slider.py 3.79 KB
Newer Older
tilman's avatar
tilman committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from __future__ import print_function
from __future__ import division
import cv2 as cv
import argparse
import numpy as np



title_window = 'Linear Blend'

def auto_canny(image, sigma=0.33):
	# compute the median of the single channel pixel intensities
	v = np.median(image)
 
	# apply automatic Canny edge detection using the computed median
	lower = int(max(0, (1.0 - sigma) * v))
	upper = int(min(255, (1.0 + sigma) * v))
	edged = cv.Canny(image, lower, upper)
	return edged

#src1 = cv.imread('/Users/Tilman/Documents/Programme/Python/forschungspraktikum/openpose/examples/media/art/28165_gw.jpg')
#src2 = cv.imread('/Users/Tilman/Documents/Programme/Python/forschungspraktikum/openpose/examples/media/art/38172_gw.jpg')
tilman's avatar
tilman committed
23
image = cv.imread('../images/out/fuse_1_bsds500/0.png')
tilman's avatar
tilman committed
24
25
26
27
28
29
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (3, 3), 0)

auto = auto_canny(blurred)

rho=3
tilman's avatar
tilman committed
30
theta=4
tilman's avatar
tilman committed
31
threshold=100
tilman's avatar
tilman committed
32
33
minline=220
maxgap=30
tilman's avatar
tilman committed
34
gauss=11
tilman's avatar
tilman committed
35
36

def on_rho(val):
tilman's avatar
tilman committed
37
    if(val<=0): return
tilman's avatar
tilman committed
38
39
40
41
    global rho
    rho=val
    update()
def on_theta(val):
tilman's avatar
tilman committed
42
    if(val<=0): return
tilman's avatar
tilman committed
43
44
45
46
    global theta
    theta=val
    update()
def on_threshold(val):
tilman's avatar
tilman committed
47
    if(val<=0): return
tilman's avatar
tilman committed
48
49
50
51
    global threshold
    threshold=val
    update()
def on_minline(val):
tilman's avatar
tilman committed
52
    if(val<=0): return
tilman's avatar
tilman committed
53
54
55
56
    global minline
    minline=val
    update()
def on_maxgap(val):
tilman's avatar
tilman committed
57
    if(val<=0): return
tilman's avatar
tilman committed
58
59
60
    global maxgap
    maxgap=val
    update()
tilman's avatar
tilman committed
61
62
63
64
65
66
def on_gauss(val):
    if(val<=0): return
    global gauss
    gauss=val
    update()

67
DISPLAY_RASTER_ELEMENTS=500
tilman's avatar
tilman committed
68
def update():
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    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)
tilman's avatar
tilman committed
87
88
89
90
    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)
tilman's avatar
tilman committed
91
    # if(lines):
tilman's avatar
tilman committed
92
93
94
95
96
97
98
99
    # 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)
100
101
102
103
104
105
106
107
108
109
110
111
    # 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))
tilman's avatar
tilman committed
112

113
    #         cv.line(blurred,(x1,y1),(x2,y2),(0,0,255),2)
tilman's avatar
tilman committed
114
    cv.imshow("Original", blurred)
tilman's avatar
tilman committed
115
116
117
118
119
120


cv.namedWindow("Original", cv.WINDOW_NORMAL)

cv.createTrackbar("rho", "Original" , 0, 50, on_rho)
cv.createTrackbar("theta", "Original" , 0, 360, on_theta)
tilman's avatar
tilman committed
121
cv.createTrackbar("threshold", "Original" , 0, 9000, on_threshold)
tilman's avatar
tilman committed
122
123
cv.createTrackbar("minline", "Original" , 0, 500, on_minline)
cv.createTrackbar("maxgap", "Original" , 0, 100, on_maxgap)
124
cv.createTrackbar("gauss", "Original" , 0, 500, on_gauss)
tilman's avatar
tilman committed
125
126
127
128
update()

cv.waitKey(0)
cv.destroyAllWindows()