-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject Tracking color
40 lines (31 loc) · 997 Bytes
/
Object Tracking color
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
import numpy as np
import cv2
def main():
cap = cv2.VideoCapture(0)
if cap.isOpened():
ret,frame = cap.read()
else:
ret = False
while ret:
ret,frame = cap.read()
hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
#blue color
# low = np.array([100,50,50])
# high = np.array([140,255,255])
#green color
# low = np.array([40,50,50])
# high = np.array([80,255,255])
#red color
low = np.array([140,50,50])
high = np.array([180,255,255])
image_mask = cv2.inRange(hsv,low,high)
output = cv2.bitwise_and(frame,frame,mask = image_mask)
cv2.imshow("Blue masked",image_mask)
cv2.imshow("Original Video Feed",frame)
cv2.imshow("Color Tracking",output)
if cv2.waitKey(1) == 27:
break
cv2.destroyAllWindows()
cap.release()
if __name__ == "__main__":
main()