aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/utils/tobii_segment_gaze_movements_export.py124
1 files changed, 30 insertions, 94 deletions
diff --git a/src/argaze/utils/tobii_segment_gaze_movements_export.py b/src/argaze/utils/tobii_segment_gaze_movements_export.py
index d47d797..8babf36 100644
--- a/src/argaze/utils/tobii_segment_gaze_movements_export.py
+++ b/src/argaze/utils/tobii_segment_gaze_movements_export.py
@@ -269,6 +269,9 @@ def main():
ts_status.to_json(gaze_status_json_filepath)
print(f'Gaze status saved into {gaze_status_json_filepath}')
+ # DEBUG
+ ts_status.as_dataframe().to_csv(f'{destination_path}/gaze_status.csv')
+
# Prepare video exportation at the same format than segment video
output_video = TobiiVideo.TobiiVideoOutput(gaze_status_video_filepath, tobii_segment_video.stream)
@@ -335,31 +338,6 @@ def main():
current_fixation_time_counter += 1
- # Draw all fixation gaze positions
- try:
-
- # Get next fixation position
- ts_next, _ = current_fixation.positions.first
-
- # Check next fixation positions is not after current time
- while ts_next < video_ts:
-
- ts_start, start_gaze_position = current_fixation.positions.pop_first()
- ts_next, next_gaze_position = current_fixation.positions.first
-
- # Draw movement
- if start_gaze_position.valid and next_gaze_position.valid:
-
- int_start_position = (int(start_gaze_position[0]), int(start_gaze_position[1]))
- int_next_position = (int(next_gaze_position[0]), int(next_gaze_position[1]))
-
- cv.line(visu_matrix, int_start_position, int_next_position, (0, 255, 0), 3)
- cv.line(gaze_status_matrix, int_start_position, int_next_position, (0, 255, 0), 3)
-
- # Empty gaze position
- except IndexError:
- pass
-
# Draw current fixation
cv.circle(visu_matrix, (int(current_fixation.centroid[0]), int(current_fixation.centroid[1])), int(current_fixation.dispersion), (0, 255, 0), current_fixation_time_counter)
cv.circle(gaze_status_matrix, (int(current_fixation.centroid[0]), int(current_fixation.centroid[1])), int(current_fixation.dispersion), (0, 255, 0))
@@ -373,31 +351,7 @@ def main():
# While current time belongs to the current saccade
if video_ts >= current_saccade_ts and video_ts <= current_saccade_ts + current_saccade.duration:
-
- # Draw all saccade gaze positions
- try:
-
- # Get next saccade position
- ts_next, _ = current_saccade.positions.first
-
- # Check next saccade positions is not after current time
- while ts_next < video_ts:
-
- ts_start, start_gaze_position = current_saccade.positions.pop_first()
- ts_next, next_gaze_position = current_saccade.positions.first
-
- # Draw movement
- if start_gaze_position.valid and next_gaze_position.valid:
-
- int_start_position = (int(start_gaze_position[0]), int(start_gaze_position[1]))
- int_next_position = (int(next_gaze_position[0]), int(next_gaze_position[1]))
-
- cv.line(visu_matrix, int_start_position, int_next_position, (0, 0, 255), 3)
- cv.line(gaze_status_matrix, int_start_position, int_next_position, (0, 0, 255), 3)
-
- # Empty gaze position
- except IndexError:
- pass
+ pass
if unknown_exist:
@@ -408,62 +362,44 @@ def main():
# While current time belongs to the current unknown movement
if video_ts >= current_unknown_ts and video_ts <= current_unknown_ts + current_unknown.duration:
+ pass
- # Draw all unknown gaze positions
- try:
-
- # Get next unknown position
- ts_next, _ = current_unknown.positions.first
-
- # Check next unknown positions is not after current time
- while ts_next < video_ts:
-
- ts_start, start_gaze_position = current_unknown.positions.pop_first()
- ts_next, next_gaze_position = current_unknown.positions.first
-
- # Draw movement
- if start_gaze_position.valid and next_gaze_position.valid:
-
- int_start_position = (int(start_gaze_position[0]), int(start_gaze_position[1]))
- int_next_position = (int(next_gaze_position[0]), int(next_gaze_position[1]))
+ # Draw all next gaze status
+ try:
- cv.line(visu_matrix, int_start_position, int_next_position, (255, 0, 0), 3)
- cv.line(gaze_status_matrix, int_start_position, int_next_position, (255, 0, 0), 3)
+ # Get next gaze status
+ ts_next, next_gaze_status = ts_status.first
- # Empty gaze position
- except IndexError:
- pass
+ # Check next gaze status is not after current time
+ while ts_next <= video_ts:
- # Draw all next gaze positions
- try:
+ ts_start, start_gaze_status = ts_status.pop_first()
+ ts_next, next_gaze_status = ts_status.first
- # Get next gaze position
- ts_next, next_gaze_position = ts_gaze_positions.first
+ # Draw movement type
+ if start_gaze_status.movement_index == next_gaze_status.movement_index \
+ and start_gaze_status.movement_type == next_gaze_status.movement_type:
- # Check next gaze position is not after current time
- while ts_next < video_ts:
+ if next_gaze_status.movement_type == 'Fixation':
+ movement_color = (0, 255, 0)
+ elif next_gaze_status.movement_type == 'Saccade':
+ movement_color = (0, 0, 255)
+ else:
+ movement_color = (255, 0, 0)
- ts_start, start_gaze_position = ts_gaze_positions.pop_first()
- ts_next, next_gaze_position = ts_gaze_positions.first
+ cv.line(visu_matrix, start_gaze_status, next_gaze_status, movement_color, 3)
+ cv.line(gaze_status_matrix, start_gaze_status, next_gaze_status, movement_color, 3)
# Draw movement
- if start_gaze_position.valid and next_gaze_position.valid:
-
- int_start_position = (int(start_gaze_position[0]), int(start_gaze_position[1]))
- int_next_position = (int(next_gaze_position[0]), int(next_gaze_position[1]))
-
- cv.line(visu_matrix, int_start_position, int_next_position, (0, 255, 255), 1)
- cv.line(gaze_status_matrix, int_start_position, int_next_position, (0, 255, 255), 1)
+ cv.line(visu_matrix, start_gaze_status, next_gaze_status, (0, 255, 255), 1)
+ cv.line(gaze_status_matrix, start_gaze_status, next_gaze_status, (0, 255, 255), 1)
# Draw gaze
- next_gaze_position.draw(visu_matrix)
- next_gaze_position.draw(gaze_status_matrix)
-
- # Write last gaze position
- if next_gaze_position.valid:
+ next_gaze_status.draw(visu_matrix)
+ next_gaze_status.draw(gaze_status_matrix)
- int_next_position = (int(next_gaze_position[0]), int(next_gaze_position[1]))
- cv.putText(visu_matrix, str(int_next_position), int_next_position, cv.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv.LINE_AA)
+ # Write last gaze status
+ cv.putText(visu_matrix, str(next_gaze_status.value), next_gaze_status.value, cv.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv.LINE_AA)
# Empty gaze position
except IndexError: