From a0cac315d63debcaa5e86d8daca2456548d42dd8 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 30 Aug 2023 13:57:44 +0200 Subject: Improving drawing features to allow fine tuning thru JSON configuration file. --- src/argaze/GazeAnalysis/DeviationCircleCoverage.py | 8 ++-- src/argaze/GazeAnalysis/FocusPointInside.py | 43 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/argaze/GazeAnalysis/DeviationCircleCoverage.py b/src/argaze/GazeAnalysis/DeviationCircleCoverage.py index d4fae2a..f938a3c 100644 --- a/src/argaze/GazeAnalysis/DeviationCircleCoverage.py +++ b/src/argaze/GazeAnalysis/DeviationCircleCoverage.py @@ -95,6 +95,8 @@ class AOIMatcher(GazeFeatures.AOIMatcher): draw_matched_fixation_positions: GazeMovement.draw_positions parameters (if None, no fixation is drawn) draw_matched_region: AOIFeatures.AOI.draw parameters (if None, no matched region is drawn) draw_looked_aoi: AOIFeatures.AOI.draw parameters (if None, no looked aoi is drawn) + looked_aoi_name_color: color of text (if None, no looked aoi name is drawn) + looked_aoi_name_offset: ofset of text from the upper left aoi bounding box corner """ if self.__matched_gaze_movement: @@ -114,9 +116,6 @@ class AOIMatcher(GazeFeatures.AOIMatcher): # Draw matched aoi if self.looked_aoi.all() != None: - # BAD: we use deviation_max attribute which is an atttribute of DispersionThresholdIdentification.Fixation class - matched_region, aoi_ratio, circle_ratio = self.looked_aoi.circle_intersection(self.__matched_gaze_movement.focus, self.__matched_gaze_movement.deviation_max) - # Draw looked aoi if required if draw_looked_aoi: @@ -125,6 +124,9 @@ 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) # Draw looked aoi name if required diff --git a/src/argaze/GazeAnalysis/FocusPointInside.py b/src/argaze/GazeAnalysis/FocusPointInside.py index d3073b5..2ac4411 100644 --- a/src/argaze/GazeAnalysis/FocusPointInside.py +++ b/src/argaze/GazeAnalysis/FocusPointInside.py @@ -29,6 +29,7 @@ class AOIMatcher(GazeFeatures.AOIMatcher): """Init looked aoi data.""" self.__looked_aoi_data = (None, None) + self.__matched_gaze_movement = None def match(self, aoi_scene, gaze_movement, exclude=[]) -> Tuple[str, AOIFeatures.AreaOfInterest]: """Returns AOI containing fixation focus point.""" @@ -42,12 +43,54 @@ class AOIMatcher(GazeFeatures.AOIMatcher): # Update looked aoi data self.__looked_aoi_data = (name, aoi) + # Update matched gaze movement + self.__matched_gaze_movement = gaze_movement + return self.__looked_aoi_data elif GazeFeatures.is_saccade(gaze_movement): self.__post_init__() + def draw(self, image: numpy.array, draw_matched_fixation: dict = None, draw_matched_fixation_positions: dict = None, draw_looked_aoi: dict = None, looked_aoi_name_color: tuple = None, looked_aoi_name_offset: tuple = (0, 0)): + """Draw matching into image. + + Parameters: + draw_matched_fixation: Fixation.draw parameters (which depends of the loaded gaze movement identifier module, if None, no fixation is drawn) + draw_matched_fixation_positions: GazeMovement.draw_positions parameters (if None, no fixation is drawn) + draw_looked_aoi: AOIFeatures.AOI.draw parameters (if None, no looked aoi is drawn) + looked_aoi_name_color: color of text (if None, no looked aoi name is drawn) + looked_aoi_name_offset: ofset of text from the upper left aoi bounding box corner + """ + + if self.__matched_gaze_movement: + + if GazeFeatures.is_fixation(self.__matched_gaze_movement): + + # Draw matched fixation if required + if draw_matched_fixation: + + self.__matched_gaze_movement.draw(image, **draw_matched_fixation) + + # Draw matched fixation positions if required + if draw_matched_fixation_positions: + + self.__matched_gaze_movement.draw_positions(image, **draw_matched_fixation_positions) + + # Draw matched aoi + if self.looked_aoi.all() != None: + + # Draw looked aoi if required + if draw_looked_aoi: + + self.looked_aoi.draw(image, **draw_looked_aoi) + + # Draw looked aoi name if required + if looked_aoi_name_color: + + top_left_corner_pixel = numpy.rint(self.looked_aoi.bounding_box[0]).astype(int) + looked_aoi_name_offset + cv2.putText(image, self.looked_aoi_name, top_left_corner_pixel, cv2.FONT_HERSHEY_SIMPLEX, 1, looked_aoi_name_color, 1, cv2.LINE_AA) + @property def looked_aoi(self) -> AOIFeatures.AreaOfInterest: """Get most likely looked aoi for current fixation (e.g. the aoi with the highest coverage mean value)""" -- cgit v1.1