forked from alamo3/opencv-gdsc-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_4.py
36 lines (22 loc) · 798 Bytes
/
ex_4.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
# get the edges of the objects in an image
import cv2
img = cv2.imread('window.jpeg')
cv2.namedWindow('Original Image', cv2.WINDOW_NORMAL)
cv2.namedWindow('Edge detection', cv2.WINDOW_NORMAL)
canny_lower = 0
canny_upper = 0
def changeCannyLower(*args):
global canny_lower
canny_lower = args[0]
def changeCannyUpper(*args):
global canny_upper
canny_upper = args[0]
cv2.createTrackbar('Lower threshold', 'Edge detection', 0, 255, changeCannyLower)
cv2.createTrackbar('Upper threshold', 'Edge detection', 0, 255, changeCannyUpper)
def edge_detection():
edge = cv2.Canny(img, canny_lower, canny_upper)
cv2.imshow('Original Image', img)
cv2.imshow('Edge detection', edge)
while True:
edge_detection()
cv2.waitKey(10)