-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblue_id.py
More file actions
38 lines (33 loc) · 884 Bytes
/
blue_id.py
File metadata and controls
38 lines (33 loc) · 884 Bytes
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
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
nzCount = 0
flag = 0
temp = 0
while (1):
ret, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_blue = np.array([50, 50, 110])
upper_blue = np.array([200, 255, 255])
mask = cv2.inRange(hsv, lower_blue, upper_blue)
res = cv2.bitwise_and(frame, frame, mask=mask)
nzCount = cv2.countNonZero(mask)
if nzCount > width * height / 30:
flag = 1
else:
flag = 0
if flag == 1:
cv2.imshow('res', res)
elif flag == 0:
cv2.imshow('res', frame)
k = cv2.waitKey(5) & 0xFF
if k == 0:
temp = 1
if k == 27:
break
cv2.destroyAllWindows()
cap.release()