From a9e44d6a3c91a9945a540310f575a955f6a4e020 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Fri, 25 Nov 2022 12:58:20 +0100 Subject: Improving fixation and saccade drawing. --- .../utils/tobii_segment_gaze_movements_export.py | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/argaze/utils/tobii_segment_gaze_movements_export.py b/src/argaze/utils/tobii_segment_gaze_movements_export.py index b61c323..1ffc836 100644 --- a/src/argaze/utils/tobii_segment_gaze_movements_export.py +++ b/src/argaze/utils/tobii_segment_gaze_movements_export.py @@ -180,35 +180,39 @@ def main(): current_fixation_time_counter = 0 current_saccade_ts, current_saccade = ts_saccades.pop_first() - + # Iterate on video frames for video_ts, video_frame in tobii_segment_video.frames(): - # Draw current fixation - if len(ts_fixations) > 0: + # While current time belongs to the current fixation + if video_ts >= current_fixation_ts and video_ts < current_fixation_ts + current_fixation.duration: - if video_ts > current_fixation_ts + current_fixation.duration: + current_fixation_time_counter += 1 - current_fixation_ts, current_fixation = ts_fixations.pop_first() - current_fixation_time_counter = 1 + # Draw current fixation + cv.circle(video_frame.matrix, (int(current_fixation.centroid[0]), int(current_fixation.centroid[1])), int(current_fixation.dispersion), (0, 255, 0), current_fixation_time_counter) - # Draw saccade - if len(ts_saccades) > 0: + # Check next fixation + elif video_ts >= current_fixation_ts + current_fixation.duration and len(ts_fixations) > 0: - if video_ts > current_saccade_ts + current_saccade.duration: + current_fixation_ts, current_fixation = ts_fixations.pop_first() + current_fixation_time_counter = 0 - current_saccade_ts, current_saccade = ts_saccades.pop_first() - start_ts, start_position = current_saccade.positions.pop_first() - end_ts, end_position = current_saccade.positions.pop_first() + # While current time belongs to the current saccade + if video_ts >= current_saccade_ts and current_fixation_time_counter == 0: - cv.line(video_frame.matrix, start_position, end_position, (0, 0, 255), 2) + start_ts, start_position = current_saccade.positions.first + end_ts, end_position = current_saccade.positions.last - else: + # Draw saccade + cv.line(video_frame.matrix, start_position, end_position, (0, 0, 255), 2) - current_fixation_time_counter += 1 + # Check next saccade + elif video_ts >= current_saccade_ts + current_saccade.duration and len(ts_saccades) > 0: - cv.circle(video_frame.matrix, (int(current_fixation.centroid[0]), int(current_fixation.centroid[1])), int(current_fixation.dispersion), (0, 255, 0), current_fixation_time_counter) + current_saccade_ts, current_saccade = ts_saccades.pop_first() + # Check next gaze try: # Get closest gaze position before video timestamp and remove all gaze positions before -- cgit v1.1