diff options
-rw-r--r-- | src/argaze/utils/README.md | 6 | ||||
-rw-r--r-- | src/argaze/utils/display_tobii_gaze.py | 75 |
2 files changed, 81 insertions, 0 deletions
diff --git a/src/argaze/utils/README.md b/src/argaze/utils/README.md index 63d060e..c4ed010 100644 --- a/src/argaze/utils/README.md +++ b/src/argaze/utils/README.md @@ -24,6 +24,12 @@ python ./src/argaze/utils/export_calibration_board.py 7 5 5 3 -o export python ./src/argaze/utils/tobii_camera_calibration.py 7 5 5 3 -t IP_ADDRESS -o export/tobii_camera.json ``` +- Display Tobii Glasses Pro 2 gaze and camera video stream (replace IP_ADDRESS) + +``` +python ./src/argaze/utils/display_tobii_gaze.py -t IP_ADDRESS +``` + - Record a Tobii Glasses Pro 2 'Test' session for a participant '1' on Tobii interface's SD card (replace IP_ADDRESS). ``` diff --git a/src/argaze/utils/display_tobii_gaze.py b/src/argaze/utils/display_tobii_gaze.py new file mode 100644 index 0000000..8a3bb33 --- /dev/null +++ b/src/argaze/utils/display_tobii_gaze.py @@ -0,0 +1,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()
\ No newline at end of file |