-
Notifications
You must be signed in to change notification settings - Fork 0
/
square-test.py
50 lines (37 loc) · 1.12 KB
/
square-test.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
49
50
from subprocess import call
import cv2
def square_rejected():
call(["python", "square_rejected.py"])
def square_size():
call(["python", "square-size.py"])
def square_accepted():
call(["python", "square_accepted.py"])
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
while True:
_, frame = cap.read()
hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
height, width, _ = frame.shape
cx = int(width / 2)
cy = int(height / 2)
# Pick pixel value
pixel_center = hsv_frame[cy, cx]
hue_value = pixel_center[0]
color = "Undefined"
if hue_value < 5:
color = "BROWN"
square_rejected()
elif hue_value < 33:
color = "YELLOW"
square_accepted()
pixel_center_bgr = frame[cy, cx]
cv2.rectangle(frame, (cx - 220, 10), (cx + 200, 120), (255, 255, 255), -1)
cv2.putText(frame, color, (cx - 200, 100), 0, 3, (0, 0, 0), 5)
cv2.circle(frame, (cx, cy), 5, (25, 25, 25), 3)
cv2.imshow("Frame", frame)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()