-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (50 loc) · 1.8 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import cv2
from gaze_tracking import GazeTracking
import matplotlib.pyplot as plt
list_x = []
list_y = []
plot_output1 = []
plot_output2 = []
gaze = GazeTracking()
webcam = cv2.VideoCapture(0)
while True:
# We get a new frame from the webcam
_, frame = webcam.read()
# We send this frame to GazeTracking to analyze it
gaze.refresh(frame)
frame = gaze.annotated_frame()
text = ""
if gaze.is_blinking():
text = "Blinking"
elif gaze.is_right():
text = "Looking right"
elif gaze.is_left():
text = "Looking left"
elif gaze.is_center():
text = "Looking center"
# cv2.putText(frame, text, (90, 60), cv2.FONT_HERSHEY_DUPLEX, 1.6, (147, 58, 31), 2)
left_pupil_x = gaze.pupil_left_coords_x()
right_pupil_x = gaze.pupil_right_coords_x()
left_pupil_y = gaze.pupil_left_coords_y()
right_pupil_y = gaze.pupil_right_coords_y()
cv2.putText(frame, "Left pupil: " + str(left_pupil_x), (90, 130), cv2.FONT_HERSHEY_DUPLEX, 0.9, (147, 58, 31), 1)
# cv2.putText(frame, "Right pupil: " + str(right_pupil_x), (90, 165), cv2.FONT_HERSHEY_DUPLEX, 0.9, (147, 58, 31), 1)
if (left_pupil_x is None) or (right_pupil_x is None) or (left_pupil_y is None) or (right_pupil_y is None):
continue
list_x.append(left_pupil_x)
list_y.append(left_pupil_y)
a = list_x[0]
print(list_x)
# for l in list: #i를 지정해서 listi로 ? list 새로지정을 어떻게 하지.
if (left_pupil_x > a+100) or (left_pupil_x < a-100):
break
cv2.imshow("Demo", frame)
if cv2.waitKey(1) == 27:
break
# webcam = gr.inputs.Image(shape=(640,480), source="webcam")
# webapp = gr.interface.Interface(inputs=webcam, outputs="images")
# webapp.launch()
plt.plot(list_x, list_y)
plt.show()
webcam.release()
cv2.destroyAllWindows()