-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathguiutils.py
58 lines (41 loc) · 1.71 KB
/
guiutils.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
50
51
52
53
54
55
56
57
58
import cv2
class EdgeFinder:
def __init__(self, image, filter_size=1, threshold1=0, threshold2=0):
self.image = image
self._filter_size = filter_size
self._threshold1 = threshold1
self._threshold2 = threshold2
def onchangeThreshold1(pos):
self._threshold1 = pos
self._render()
def onchangeThreshold2(pos):
self._threshold2 = pos
self._render()
def onchangeFilterSize(pos):
self._filter_size = pos
self._filter_size += (self._filter_size + 1) % 2
self._render()
cv2.namedWindow('edges')
cv2.createTrackbar('threshold1', 'edges', self._threshold1, 255, onchangeThreshold1)
cv2.createTrackbar('threshold2', 'edges', self._threshold2, 255, onchangeThreshold2)
cv2.createTrackbar('filter_size', 'edges', self._filter_size, 20, onchangeFilterSize)
self._render()
print "Adjust the parameters as desired. Hit any key to close."
cv2.waitKey(0)
cv2.destroyWindow('edges')
cv2.destroyWindow('smoothed')
def threshold1(self):
return self._threshold1
def threshold2(self):
return self._threshold2
def filterSize(self):
return self._filter_size
def edgeImage(self):
return self._edge_img
def smoothedImage(self):
return self._smoothed_img
def _render(self):
self._smoothed_img = cv2.GaussianBlur(self.image, (self._filter_size, self._filter_size), sigmaX=0, sigmaY=0)
self._edge_img = cv2.Canny(self._smoothed_img, self._threshold1, self._threshold2)
cv2.imshow('smoothed', self._smoothed_img)
cv2.imshow('edges', self._edge_img)