-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
68 lines (52 loc) · 1.83 KB
/
example.py
File metadata and controls
68 lines (52 loc) · 1.83 KB
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
"""
Demonstration of the GazeTracking library.
Check the README.md for complete documentation.
"""
import dlib
import pandas as pd
from matplotlib import pyplot as plt
import cv2
from gaze_tracking import GazeTracking
import gaze_tracking
#from Visualization import Visualization
gaze = GazeTracking()
webcam = cv2.VideoCapture(0)
webcam.set(cv2.CAP_PROP_FRAME_WIDTH, 1366)
webcam.set(cv2.CAP_PROP_FRAME_HEIGHT, 768)
#image = cv2.imread(gaze_tracking.path)
while True:
# We get a new frame from the webcam
_, frame = webcam.read()
#out.write(frame)
# We send this frame to GazeTracking to analyze it
gaze.refresh(frame)
frame = gaze.annotated_frame()
#image=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 = gaze.pupil_left_coords()
right_pupil = gaze.pupil_right_coords()
cv2.putText(frame, "Left pupil: " + str(left_pupil), (90, 130), cv2.FONT_HERSHEY_DUPLEX, 0.9, (147, 58, 31), 1)
cv2.putText(frame, "Right pupil: " + str(right_pupil), (90, 165), cv2.FONT_HERSHEY_DUPLEX, 0.9, (147, 58, 31), 1)
cv2.imshow("Demo", frame)
if cv2.waitKey(1) == 27:
break
#out.release()
class Visualization():
df = pd.read_csv("data_csv.csv", names=['xleft','yleft','xright','yright','xrightyleft','xleftyright'])
plt.plot(df.xleft, df.yleft)
plt.plot(df.xright, df.yright)
#plt.plot((df.xleft + df.yleft) / 2, (df.xright + df.yright) / 2)
plt.xlabel('X-coordinate')
plt.ylabel('Y-coordinate')
plt.legend(['Left Eye', 'Right Eye'])
plt.show()
plot = Visualization()