aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/argaze/utils/tobii_segment_gaze_movements_export.py47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/argaze/utils/tobii_segment_gaze_movements_export.py b/src/argaze/utils/tobii_segment_gaze_movements_export.py
index 0049e15..b61c323 100644
--- a/src/argaze/utils/tobii_segment_gaze_movements_export.py
+++ b/src/argaze/utils/tobii_segment_gaze_movements_export.py
@@ -4,6 +4,7 @@ import argparse
import os
from argaze import GazeFeatures
+from argaze.GazeAnalysis import DispersionBasedGazeMovementIdentifier
from argaze.TobiiGlassesPro2 import TobiiEntities, TobiiVideo, TobiiSpecifications
from argaze.utils import MiscFeatures
@@ -115,35 +116,35 @@ def main():
print(f'\tDuration threshold = {args.duration_threshold}')
# Start movement identification
- movement_identifier = GazeFeatures.DispersionBasedGazeMovementIdentifier(ts_gaze_positions, args.dispersion_threshold, args.duration_threshold*1e3)
- fixations = GazeFeatures.TimeStampedGazeMovements()
- saccades = GazeFeatures.TimeStampedGazeMovements()
- gaze_status = GazeFeatures.TimeStampedGazeStatus()
+ movement_identifier = DispersionBasedGazeMovementIdentifier.GazeMovementIdentifier(args.dispersion_threshold, args.duration_threshold*1e3)
+ ts_fixations = GazeFeatures.TimeStampedGazeMovements()
+ ts_saccades = GazeFeatures.TimeStampedGazeMovements()
+ ts_status = GazeFeatures.TimeStampedGazeStatus()
# Initialise progress bar
MiscFeatures.printProgressBar(0, tobii_segment_video.duration, prefix = 'GazeMovements identification:', suffix = 'Complete', length = 100)
- for gaze_movement in movement_identifier:
+ for gaze_movement in movement_identifier(ts_gaze_positions):
- if isinstance(gaze_movement, GazeFeatures.DispersionBasedGazeMovementIdentifier.DispersionBasedFixation):
+ if isinstance(gaze_movement, DispersionBasedGazeMovementIdentifier.Fixation):
start_ts, start_position = gaze_movement.positions.first
- fixations[start_ts] = gaze_movement
+ ts_fixations[start_ts] = gaze_movement
for ts, position in gaze_movement.positions.items():
- gaze_status[ts] = GazeFeatures.GazeStatus(position, 'Fixation', len(fixations))
+ ts_status[ts] = GazeFeatures.GazeStatus.from_position(position, 'Fixation', len(ts_fixations))
- elif isinstance(gaze_movement, GazeFeatures.DispersionBasedGazeMovementIdentifier.DispersionBasedSaccade):
+ elif isinstance(gaze_movement, DispersionBasedGazeMovementIdentifier.Saccade):
start_ts, start_position = gaze_movement.positions.first
end_ts, end_position = gaze_movement.positions.last
- saccades[start_ts] = gaze_movement
+ ts_saccades[start_ts] = gaze_movement
- gaze_status[start_ts] = GazeFeatures.GazeStatus(start_position, 'Saccade', len(saccades))
- gaze_status[end_ts] = GazeFeatures.GazeStatus(end_position, 'Saccade', len(saccades))
+ ts_status[start_ts] = GazeFeatures.GazeStatus.from_position(start_position, 'Saccade', len(ts_saccades))
+ ts_status[end_ts] = GazeFeatures.GazeStatus.from_position(end_position, 'Saccade', len(ts_saccades))
else:
continue
@@ -152,18 +153,18 @@ def main():
progress = ts - int(args.time_range[0] * 1e6)
MiscFeatures.printProgressBar(progress, tobii_segment_video.duration, prefix = 'GazeMovements identification:', suffix = 'Complete', length = 100)
- print(f'\n{len(fixations)} fixations and {len(saccades)} saccades found')
+ print(f'\n{len(ts_fixations)} fixations and {len(ts_saccades)} saccades found')
# Export fixations analysis
- fixations.as_dataframe().to_csv(fixations_filepath, index=True)
+ ts_fixations.as_dataframe().to_csv(fixations_filepath, index=True)
print(f'Fixations saved into {fixations_filepath}')
# Export saccades analysis
- saccades.as_dataframe().to_csv(saccades_filepath, index=True)
+ ts_saccades.as_dataframe().to_csv(saccades_filepath, index=True)
print(f'Saccades saved into {saccades_filepath}')
# Export gaze status analysis
- gaze_status.as_dataframe().to_csv(gaze_status_filepath, index=True)
+ ts_status.as_dataframe().to_csv(gaze_status_filepath, index=True)
print(f'Gaze status saved into {gaze_status_filepath}')
# Prepare video exportation at the same format than segment video
@@ -175,28 +176,28 @@ def main():
# Initialise progress bar
MiscFeatures.printProgressBar(0, tobii_segment_video.duration, prefix = 'Video with movements processing:', suffix = 'Complete', length = 100)
- current_fixation_ts, current_fixation = fixations.pop_first()
+ current_fixation_ts, current_fixation = ts_fixations.pop_first()
current_fixation_time_counter = 0
- current_saccade_ts, current_saccade = saccades.pop_first()
+ 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(fixations) > 0:
+ if len(ts_fixations) > 0:
if video_ts > current_fixation_ts + current_fixation.duration:
- current_fixation_ts, current_fixation = fixations.pop_first()
+ current_fixation_ts, current_fixation = ts_fixations.pop_first()
current_fixation_time_counter = 1
# Draw saccade
- if len(saccades) > 0:
+ if len(ts_saccades) > 0:
if video_ts > current_saccade_ts + current_saccade.duration:
- current_saccade_ts, current_saccade = saccades.pop_first()
+ 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()
@@ -206,7 +207,7 @@ def main():
current_fixation_time_counter += 1
- cv.circle(video_frame.matrix, current_fixation.centroid, current_fixation.dispersion, (0, 255, 0), current_fixation_time_counter)
+ 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)
try: