-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCanny Edge Detector Real-time.py
48 lines (31 loc) · 1.09 KB
/
Canny Edge Detector Real-time.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
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
# loop runs if capturing has been initialized
while 1:
ret, frame = cap.read()
# converting BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of red color in HSV
lower_red = np.array([5,50,50])
upper_red = np.array([15,255,255])
# create a red HSV colour boundary and
# threshold HSV image
mask = cv2.inRange(hsv, lower_red, upper_red)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
# Display an original image
cv2.imshow('Original',frame)
# finds edges in the input image image and
# marks them in the output map edges
edges = cv2.Canny(frame,100,200)
# Display edges in a frame
cv2.imshow('Edges',edges)
# Wait for Esc key to stop
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
# Close the window
cap.release()
# De-allocate any associated memory usage
cv2.destroyAllWindows()