diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze/utils/replay_tobii_session.py | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/src/argaze/utils/replay_tobii_session.py b/src/argaze/utils/replay_tobii_session.py index d001889..785f254 100644 --- a/src/argaze/utils/replay_tobii_session.py +++ b/src/argaze/utils/replay_tobii_session.py @@ -4,6 +4,7 @@ import argparse from argaze import GazeFeatures from argaze.TobiiGlassesPro2 import TobiiEntities, TobiiVideo, TobiiData +from argaze.utils import MiscFeatures import numpy @@ -41,13 +42,12 @@ def main(): tobii_ts_pupil_diameter = tobii_segment_data.gidx_pd_eye print(f'{len(tobii_ts_pupil_diameter)} pupil diameters loaded') - # Prepare video exportation at the same format than segment video - gaze_video_filepath = f'{args.segment_path}/gaze.mp4' - output_video = TobiiVideo.TobiiVideoOutput(gaze_video_filepath, tobii_segment_video.get_stream()) - # Video and data replay loop try: + # Initialise progress bar + MiscFeatures.printProgressBar(0, tobii_segment_video.get_duration(), prefix = 'Video progression:', suffix = 'Complete', length = 100) + # Iterate on video frames for video_ts, video_frame in tobii_segment_video.frames(): @@ -56,36 +56,29 @@ def main(): # Get closest gaze position before video timestamp and remove all gaze positions before closest_gaze_ts, closest_gaze_position = tobii_ts_gaze_positions.pop_first_until(video_ts) + # Get closest pupil diameter before video timestamp and remove all pupil diameters before + closest_pupil_ts, closest_pupil_diameter = tobii_ts_pupil_diameter.pop_first_until(video_ts) + # Draw gaze position gaze_position = (int(closest_gaze_position.gp[0] * video_frame.width), int(closest_gaze_position.gp[1] * video_frame.height)) - cv.circle(video_frame.matrix, gaze_position, 4, (0, 255, 255), -1) + pupil_diameter = int((10 - closest_pupil_diameter.pd) / 2) + + cv.circle(video_frame.matrix, gaze_position, 10, (0, 255, 255), pupil_diameter) # Wait for gaze position except ValueError: continue - - try: - - # Get closest pupil diameter before video timestamp and remove all pupil diameters before - closest_pupil_ts, closest_pupil_diameter = tobii_ts_pupil_diameter.pop_first_until(video_ts) - - # Draw pupil diameter - pupil_diameter = int(closest_pupil_diameter.pd * 2) - cv.circle(video_frame.matrix, gaze_position, pupil_diameter, (255, 0, 255), 1) - - # Write video - output_video.write(video_frame.matrix) - - # Ignore missing pupil diameter - except ValueError: - pass - + # Close window using 'Esc' key if cv.waitKey(1) == 27: break 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) + # Exit on 'ctrl+C' interruption except KeyboardInterrupt: pass @@ -93,10 +86,6 @@ def main(): # Stop frame display cv.destroyAllWindows() - # End output video file - output_video.close() - print(f'\nVideo with gaze data saved into {gaze_video_filepath}') - if __name__ == '__main__': main()
\ No newline at end of file |