forked from CSAILVision/GazeCapture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liveGazeCapture.py
56 lines (42 loc) · 1.19 KB
/
liveGazeCapture.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
import cv2
import faceDetection
import visualizeGaze
import iTracker
import numpy as np
import sys
MOVING_AVG = 3
def liveGazeCapture(config):
# Initialize iTracker and face detection
itrack = iTracker.iTracker()
detector = faceDetection.faceDetection()
# Initialize cam
cap = cv2.VideoCapture(0)
ret, img = cap.read()
cv2.namedWindow("image")
cv2.imshow("image",img)
cv2.waitKey(500)
# Initialize reslt visualization
vis = visualizeGaze.visualize(config)
# Initialize MA filter
coords_array = np.zeros((3,2))
ma_counter = 0
while True:
ret, img = cap.read()
img = img[:,80:510,:]
images = detector.detect(img, DRAW=0)
if images is None:
continue
coords = itrack.infer(images) # x, y in cm
coords_array[ma_counter, :] = coords
coords_filtered = np.mean(coords_array, axis=0)
if ma_counter < MOVING_AVG - 1:
ma_counter += 1
else:
ma_counter = 0
vis.showGaze(coords_filtered)
if __name__ == "__main__":
if len(sys.argv) > 1:
config = map(int, sys.argv[1])[0]
else:
config = 0
liveGazeCapture(config)