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
69
70
71
72
73
74
75
|
#!/usr/bin/env python
import argparse
import os, time
from argaze.TobiiGlassesPro2 import *
import cv2 as cv
import numpy
def main():
"""
Capture video camera and display gaze point
"""
# manage arguments
parser = argparse.ArgumentParser(description=main.__doc__.split('-')[0])
parser.add_argument('-t', '--tobii_ip', metavar='TOBII_IP', type=str, default='192.168.1.10', help='tobii glasses ip')
args = parser.parse_args()
# create tobii controller
tobii_controller = TobiiController.TobiiController(args.tobii_ip, 'ArGaze', 1)
# calibrate tobii glasses
#tobii_controller.calibrate()
# create tobii data thread
tobii_data_thread = TobiiData.TobiiDataThread(tobii_controller)
tobii_data_thread.start()
# create tobii video thread
tobii_video_thread = TobiiVideo.TobiiVideoThread(tobii_controller)
tobii_video_thread.start()
# start tobii glasses streaming
tobii_controller.start_streaming()
# display loop
try:
# wait 1ms between each frame until 'Esc' key is pressed
while cv.waitKey(1) != 27:
frame, frame_width, frame_height, frame_time, pts = tobii_video_thread.read()
# draw tobii gaze
# TODO : sync gaze data according frame pts
gp_data = tobii_data_thread.read_gaze_data(pts)
if 'TIMESTAMP' in gp_data:
pointer = (int(gp_data['X'] * frame_width), int(gp_data['Y'] * frame_height))
cv.circle(frame, pointer, 4, (0, 255, 255), -1)
else:
pointer = (0, 0)
# display frame
cv.imshow('Tobii Camera Record', frame)
# exit on 'ctrl+C' interruption
except KeyboardInterrupt:
pass
# stop frame display
cv.destroyAllWindows()
# stop tobii objects
tobii_video_thread.stop()
tobii_data_thread.stop()
tobii_controller.stop_streaming()
tobii_controller.close()
if __name__ == '__main__':
main()
|