-
Notifications
You must be signed in to change notification settings - Fork 0
/
cannytester.py
49 lines (38 loc) · 1.54 KB
/
cannytester.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# script for tuning parameters
import cv2
import numpy as np
import argparse
# parse argument
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = "Path to the image")
args = vars(ap.parse_args())
# reads the image
img = cv2.imread(args['image'])
# empty callback function for creating trackar
def callback(foo):
pass
# create windows and trackbar
cv2.namedWindow('parameters')
cv2.createTrackbar('threshold1', 'parameters', 0, 500, callback) # change the maximum to whatever you like
cv2.createTrackbar('threshold2', 'parameters', 0, 500, callback) # change the maximum to whatever you like
cv2.createTrackbar('apertureSize', 'parameters', 0,2, callback)
cv2.createTrackbar('L1/L2', 'parameters', 0, 1, callback)
while(True):
# get threshold value from trackbar
th1 = cv2.getTrackbarPos('threshold1', 'parameters')
th2 = cv2.getTrackbarPos('threshold2', 'parameters')
# aperture size can only be 3,5, or 7
apSize = cv2.getTrackbarPos('apertureSize', 'parameters')*2+3
# true or false for the norm flag
norm_flag = cv2.getTrackbarPos('L1/L2', 'parameters') == 1
# print out the values
print('')
print('threshold1: {}'.format(th1))
print('threshold2: {}'.format(th2))
print('apertureSize: {}'.format(apSize))
print('L2gradient: {}'.format(norm_flag))
edge = cv2.Canny(img, th1, th2, apertureSize=apSize, L2gradient=norm_flag)
cv2.imshow('canny', edge)
if cv2.waitKey(1)&0xFF == ord('q'):
break
cv2.destroyAllWindows()