From 3176cb6fb4ac47a5bccd2aa2f1b8eab3a5594853 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 11 May 2022 18:52:52 +0200 Subject: Working on record and replay events and variables. --- src/argaze/utils/record_tobii_session.py | 53 ++++++++++++++++++-------------- src/argaze/utils/replay_tobii_session.py | 39 ++++++++++++++++++----- 2 files changed, 62 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/argaze/utils/record_tobii_session.py b/src/argaze/utils/record_tobii_session.py index 070563f..a45727b 100644 --- a/src/argaze/utils/record_tobii_session.py +++ b/src/argaze/utils/record_tobii_session.py @@ -1,10 +1,12 @@ #!/usr/bin/env python import argparse +import threading import time import random from argaze.TobiiGlassesPro2 import TobiiController +from argaze.utils import MiscFeatures def main(): """ @@ -29,42 +31,47 @@ def main(): # Start recording tobii_controller.start_recording(recording_id) + print('Recording started') - # Waiting until keyboard interruption - try: + # Define loop + last_battery_level = 0 + time_count = 0 - last_battery_level = 0 - time_count = 0 - while True: + exit = MiscFeatures.ExitSignalHandler() + print('Waiting for Ctrl+C to quit...\n') - # Print storage info each minutes - if time_count % 60 == 0: + while not exit.status(): - print(tobii_controller.get_storage_info()) + # Print storage info each minutes + if time_count % 60 == 0: - # print battery level each time it changes - battery_level = tobii_controller.get_battery_level() - if battery_level != last_battery_level: + print(tobii_controller.get_storage_info()) - print(tobii_controller.get_battery_info()) - last_battery_level = battery_level + # print battery level each time it changes + # send it as experimental variable + battery_level = tobii_controller.get_battery_level() + if battery_level != last_battery_level: - # send random event each 3 - 10 seconds - if time_count % random.randint(3, 10) == 0: + print(tobii_controller.get_battery_info()) - print('Send event') - tobii_controller.send_custom_event('TestEvent', time_count) + tobii_controller.send_variable('battery', battery_level) - # Sleep 1 second - time.sleep(1) - time_count += 1 + last_battery_level = battery_level - # exit on keyboard interruption - except KeyboardInterrupt: - pass + # send random event each 3 - 10 seconds + if time_count % random.randint(3, 10) == 0: + + print('Send random event') + + tobii_controller.send_event('random') + + # Sleep 1 second + time.sleep(1) + time_count += 1 # Stop recording tobii_controller.stop_recording(recording_id) + print('Recording stopped') if __name__ == '__main__': diff --git a/src/argaze/utils/replay_tobii_session.py b/src/argaze/utils/replay_tobii_session.py index 52c2b24..4fb9f2b 100644 --- a/src/argaze/utils/replay_tobii_session.py +++ b/src/argaze/utils/replay_tobii_session.py @@ -19,6 +19,7 @@ def main(): parser = argparse.ArgumentParser(description=main.__doc__.split('-')[0]) parser.add_argument('-s', '--segment_path', metavar='SEGMENT_PATH', type=str, default=None, help='segment path') parser.add_argument('-r', '--time_range', metavar=('START_TIME', 'END_TIME'), nargs=2, type=float, default=(0., None), help='start and end time (in second)') + parser.add_argument('-w', '--window', metavar='DISPLAY', type=bool, default=True, help='enable window display', action=argparse.BooleanOptionalAction) args = parser.parse_args() if args.segment_path != None: @@ -45,15 +46,24 @@ def main(): tobii_ts_pupil_diameter = tobii_segment_data.gidx_pd_eye print(f'{len(tobii_ts_pupil_diameter)} pupil diameters loaded') + # Access to timestamped events data buffer + tobii_ts_events = tobii_segment_data.ets_type_tag + print(f'{len(tobii_ts_events)} events loaded') + # Video and data replay loop try: # Initialise progress bar - MiscFeatures.printProgressBar(0, tobii_segment_video.get_duration(), prefix = 'Video progression:', suffix = 'Complete', length = 100) + MiscFeatures.printProgressBar(0, tobii_segment_video.get_duration()/1000, prefix = 'Video progression:', suffix = 'Complete', length = 100) # Iterate on video frames for video_ts, video_frame in tobii_segment_video.frames(): + video_ts_ms = video_ts / 1000 + + # Write segment timing + cv.putText(video_frame.matrix, f'Segment time: {int(video_ts_ms)} ms', (20, 40), cv.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv.LINE_AA) + try: # Get closest gaze position before video timestamp and remove all gaze positions before @@ -71,16 +81,31 @@ def main(): # Wait for gaze position except ValueError: continue + + try: + + # Get closest event before video timestamp and remove all gaze positions before + closest_event_ts, closest_event = tobii_ts_events.pop_first_until(video_ts) + + print(closest_event_ts/1000, closest_event) + + # Write events + cv.putText(video_frame.matrix, str(closest_event), (20, 140), cv.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv.LINE_AA) + + except ValueError: + pass + + if args.window: - # Close window using 'Esc' key - if cv.waitKey(1) == 27: - break + # Close window using 'Esc' key + if cv.waitKey(1) == 27: + break - cv.imshow(f'Segment {tobii_segment.get_id()} video', video_frame.matrix) + cv.imshow(f'Segment {tobii_segment.get_id()} video', video_frame.matrix) # Update Progress Bar - progress = video_ts - int(args.time_range[0] * 1000000) - MiscFeatures.printProgressBar(progress, tobii_segment_video.get_duration(), prefix = 'Video progression:', suffix = 'Complete', length = 100) + progress = video_ts_ms - int(args.time_range[0] * 1000) + MiscFeatures.printProgressBar(progress, tobii_segment_video.get_duration()/1000, prefix = 'Video progression:', suffix = 'Complete', length = 100) # Exit on 'ctrl+C' interruption except KeyboardInterrupt: -- cgit v1.1