Skip to content

Commit 8cf8df3

Browse files
How cv2.Canny() behaves for different values
1 parent aa7352d commit 8cf8df3

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

dynamicCannyEdgeDetection.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Dynamic Variation in Canny Edge Detection - by Changing threshold values
2+
3+
import cv2
4+
import numpy as np
5+
6+
def nothing():
7+
pass
8+
9+
img = cv2.imread("cube.jpg", 0) #Take the input image in GrayScale
10+
11+
cv2.namedWindow("Cube Canny Edge Detection") #Get a named window
12+
13+
#Set minimum and maximum value trackbar
14+
cv2.createTrackbar("Min Value", "Cube Canny Edge Detection", 0, 100, nothing)
15+
cv2.createTrackbar("Max Value", "Cube Canny Edge Detection", 0, 200, nothing)
16+
17+
while(True):
18+
19+
#Get trackbar value from the respective trackbar
20+
minV = cv2.getTrackbarPos("Min Value", "Cube Canny Edge Detection")
21+
maxV = cv2.getTrackbarPos("Max Value", "Cube Canny Edge Detection")
22+
23+
#Apply Canny Edge Detection on obtained minV and maxV
24+
res = cv2.Canny(img, minV, maxV)
25+
cv2.imshow("Cube Canny Edge Detection", res)
26+
27+
#Break when "q" key is pressed
28+
if cv2.waitKey(1) & 0xff == ord('q'):
29+
break
30+
31+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)