threshold_slider.py 2.07 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

def on_rho(val):
    global rho
    rho=val
    update()
def on_theta(val):
    global theta
    theta=val
    update()
def on_threshold(val):
    global threshold
    threshold=val
    update()
def on_minline(val):
    global minline
    minline=val
    update()
def on_maxgap(val):
    global maxgap
    maxgap=val
    update()
def update():
tilman's avatar
tilman committed
56
    image = cv.imread('../images/out/fuse_1_bsds500/1.png')
tilman's avatar
tilman committed
57
    lines = cv.HoughLinesP(image=image, rho=rho, theta=np.pi/theta, threshold=threshold, minLineLength=minline, maxLineGap=maxgap)
tilman's avatar
tilman committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    # if(lines):
    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")


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, 500, on_threshold)
cv.createTrackbar("minline", "Original" , 0, 500, on_minline)
cv.createTrackbar("maxgap", "Original" , 0, 100, on_maxgap)
update()

cv.waitKey(0)
cv.destroyAllWindows()