diff options
Diffstat (limited to 'src/argaze/utils/synchronise_timestamped_data.py')
-rw-r--r-- | src/argaze/utils/synchronise_timestamped_data.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/argaze/utils/synchronise_timestamped_data.py b/src/argaze/utils/synchronise_timestamped_data.py new file mode 100644 index 0000000..0c22072 --- /dev/null +++ b/src/argaze/utils/synchronise_timestamped_data.py @@ -0,0 +1,50 @@ + + + + + + + + # Synchronise video and gaze + vts_ts, vts = tobii_vts.pop_first() + vts_offset = (vts_ts - vts.vts) / 1000 + + print(f'Init >>> vts_offset = {vts_offset}') + + last_gaze_position_index = -1 + closest_gaze_position_ts, closest_gaze_position = None, None + + last_fixation_index = -1 + closest_fixation_ts, closest_fixation = None, None + + for frame_ts, frame in tobii_segment_video.frames(): + + frame_ts = frame_ts / 1000 + + if frame_ts > vts.vts / 1000: + if len(tobii_vts) > 0: + vts_ts, vts = tobii_vts.pop_first() + vts_offset = (vts_ts - vts.vts) / 1000 + print(f'{frame_ts / 1000} >>> New vts_offset = {vts_offset / 1000}') + + # Find closest gaze position + closest_index = bisect.bisect_left(list(generic_ts_gaze_positions.keys()), frame_ts + vts_offset) - 1 + if closest_index > last_gaze_position_index: + + # pop data until closest_index + while last_gaze_position_index <= closest_index: + closest_gaze_position_ts, closest_gaze_position = generic_ts_gaze_positions.pop_first() + last_gaze_position_index += 1 + + print(f'{frame_ts / 1000} *** New closest gaze position: index = {closest_index}, ts = {closest_gaze_position_ts / 1000}, {closest_gaze_position}') + + # Find closest fixation + closest_index = bisect.bisect_left(list(fixation_analyser.fixations.keys()), frame_ts + vts_offset) - 1 + if closest_index > last_fixation_index: + + # pop data until closest_index + while last_fixation_index <= closest_index: + closest_ts, closest_fixation = fixation_analyser.fixations.pop_first() + last_fixation_index += 1 + + print(f'{frame_ts / 1000} /// New closest fixation: index= {closest_index}, ts = {closest_ts / 1000}, {closest_fixation}')
\ No newline at end of file |