From 53d12ee867cc545fc804a1549b692dd5ab6a9387 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 30 Aug 2023 14:52:43 +0200 Subject: Keeping matched region to draw it without calculate it again. --- src/argaze/GazeAnalysis/DeviationCircleCoverage.py | 40 +++++++++++++--------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/argaze/GazeAnalysis/DeviationCircleCoverage.py b/src/argaze/GazeAnalysis/DeviationCircleCoverage.py index f938a3c..98706f7 100644 --- a/src/argaze/GazeAnalysis/DeviationCircleCoverage.py +++ b/src/argaze/GazeAnalysis/DeviationCircleCoverage.py @@ -36,6 +36,7 @@ class AOIMatcher(GazeFeatures.AOIMatcher): self.__looked_aoi_coverage_mean = 0 self.__looked_aoi_coverage = {} self.__matched_gaze_movement = None + self.__matched_region = None def match(self, aoi_scene, gaze_movement, exclude=[]) -> Tuple[str, AOIFeatures.AreaOfInterest]: """Returns AOI with the maximal fixation's deviation circle coverage if above coverage threshold.""" @@ -46,14 +47,15 @@ class AOIMatcher(GazeFeatures.AOIMatcher): max_coverage = 0. most_likely_looked_aoi_data = (None, None) + matched_region = None for name, aoi in aoi_scene.items(): - _, _, circle_ratio = aoi.circle_intersection(gaze_movement.focus, gaze_movement.deviation_max) + # BAD: we use deviation_max attribute which is an atttribute of DispersionThresholdIdentification.Fixation class + region, _, circle_ratio = aoi.circle_intersection(gaze_movement.focus, gaze_movement.deviation_max) if name not in exclude and circle_ratio > 0: - # Sum circle ratio to update aoi coverage try: @@ -63,25 +65,32 @@ class AOIMatcher(GazeFeatures.AOIMatcher): self.__looked_aoi_coverage[name] = circle_ratio - # Update most likely looked aoi + # Update maximal coverage and most likely looked aoi if self.__looked_aoi_coverage[name] > max_coverage: - most_likely_looked_aoi_data = (name, aoi) max_coverage = self.__looked_aoi_coverage[name] + most_likely_looked_aoi_data = (name, aoi) + matched_region = region + + # Check that aoi coverage happens + if max_coverage > 0: - # Update looked aoi data - self.__looked_aoi_data = most_likely_looked_aoi_data + # Update looked aoi data + self.__looked_aoi_data = most_likely_looked_aoi_data - # Update looked aoi coverage mean - self.__looked_aoi_coverage_mean = int(100 * max_coverage / self.__look_count) / 100 + # Update looked aoi coverage mean + self.__looked_aoi_coverage_mean = int(100 * max_coverage / self.__look_count) / 100 - # Update matched gaze movement - self.__matched_gaze_movement = gaze_movement if max_coverage > 0. else None + # Update matched gaze movement + self.__matched_gaze_movement = gaze_movement - # Return - if self.looked_aoi_coverage_mean > self.coverage_threshold: + # Update matched region + self.__matched_region = matched_region - return self.__looked_aoi_data + # Return + if self.looked_aoi_coverage_mean > self.coverage_threshold: + + return self.__looked_aoi_data elif GazeFeatures.is_saccade(gaze_movement): @@ -124,10 +133,7 @@ class AOIMatcher(GazeFeatures.AOIMatcher): # Draw matched region if required if draw_matched_region: - # BAD: we use deviation_max attribute which is an atttribute of DispersionThresholdIdentification.Fixation class - matched_region, _, _ = self.looked_aoi.circle_intersection(self.__matched_gaze_movement.focus, self.__matched_gaze_movement.deviation_max) - - matched_region.draw(image, **draw_matched_region) + self.__matched_region.draw(image, **draw_matched_region) # Draw looked aoi name if required if looked_aoi_name_color: -- cgit v1.1