From 7521e92b03c80c15152f0985ffc1e3af057329a9 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Fri, 9 Dec 2022 01:38:35 +0100 Subject: Merging overlapping fixations. --- .../DispersionBasedGazeMovementIdentifier.py | 4 +- .../DispersionBasedGazeMovementIdentifier.py | 43 ++++++++++++++++------ 2 files changed, 33 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/argaze.test/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py b/src/argaze.test/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py index 497a23f..0ddebc6 100644 --- a/src/argaze.test/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py +++ b/src/argaze.test/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py @@ -178,7 +178,7 @@ class TestDispersionBasedGazeMovementIdentifierClass(unittest.TestCase): # Check that fixation overlaps self.assertTrue(fixation_B.overlap(fixation_C)) self.assertTrue(fixation_C.overlap(fixation_B)) - ''' + def test_fixation_overlapping_identification(self): """Test DispersionBasedGazeMovementIdentifier identification when fixations overlap.""" @@ -210,7 +210,7 @@ class TestDispersionBasedGazeMovementIdentifierClass(unittest.TestCase): #self.assertGreaterEqual(fixation.dispersion, dispersion) self.assertGreaterEqual(fixation.duration, 2 * size * min_time) self.assertLessEqual(fixation.duration, 2 * size * max_time) - ''' + if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/src/argaze/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py b/src/argaze/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py index 8498f84..477aec5 100644 --- a/src/argaze/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py +++ b/src/argaze/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py @@ -183,27 +183,46 @@ class GazeMovementIdentifier(GazeFeatures.GazeMovementIdentifier): # is the new fixation have a duration ? if new_fixation.duration > 0: + # does a former fixation have been identified ? if self.__last_fixation != None: - # store start and end positions in a timestamped buffer - ts_saccade_positions = GazeFeatures.TimeStampedGazePositions() + # merge new fixation if it overlaps last fixation + if self.__last_fixation.overlap(new_fixation): - start_position_ts, start_position = self.__last_fixation.positions.last - ts_saccade_positions[start_position_ts] = start_position + self.__last_fixation.merge(new_fixation) + new_fixation = None - end_position_ts, end_position = new_fixation.positions.first - ts_saccade_positions[end_position_ts] = end_position + # else output last fixation and create a saccade + else: - if end_position_ts > start_position_ts: + yield self.__last_fixation + + # store start and end positions in a timestamped buffer + ts_saccade_positions = GazeFeatures.TimeStampedGazePositions() - new_saccade = Saccade(ts_saccade_positions) - - yield new_saccade + start_position_ts, start_position = self.__last_fixation.positions.last + ts_saccade_positions[start_position_ts] = start_position - self.__last_fixation = new_fixation + end_position_ts, end_position = new_fixation.positions.first + ts_saccade_positions[end_position_ts] = end_position - yield new_fixation + if end_position_ts > start_position_ts: + + new_saccade = Saccade(ts_saccade_positions) + + yield new_saccade + + self.__last_fixation = new_fixation + + else: + + self.__last_fixation = new_fixation + yield self.__last_fixation # dispersion too wide : consider next gaze position else: self.__ts_gaze_positions.pop_first() + + # output last fixation + if self.__last_fixation != None: + yield self.__last_fixation -- cgit v1.1