diff options
author | Théo de la Hogue | 2023-08-30 18:35:32 +0200 |
---|---|---|
committer | Théo de la Hogue | 2023-08-30 18:35:32 +0200 |
commit | 7ffb244289cef6d0fabee80dd369396ac845203c (patch) | |
tree | 3b7fa199f5c8f475c0893ce5eae87e0cf3c1ffb0 /src | |
parent | 3be9a7dc5a083d9476cac30128340f2bd4e0ceb0 (diff) | |
download | argaze-7ffb244289cef6d0fabee80dd369396ac845203c.zip argaze-7ffb244289cef6d0fabee80dd369396ac845203c.tar.gz argaze-7ffb244289cef6d0fabee80dd369396ac845203c.tar.bz2 argaze-7ffb244289cef6d0fabee80dd369396ac845203c.tar.xz |
Adding draw_parameters attribute to ArLayer.
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze/ArFeatures.py | 99 |
1 files changed, 62 insertions, 37 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py index 1e633ca..d92c754 100644 --- a/src/argaze/ArFeatures.py +++ b/src/argaze/ArFeatures.py @@ -65,6 +65,36 @@ class LoadingFailed(Exception): super().__init__(message) + +# Define default ArLayer draw parameters +DEFAULT_ARLAYER_DRAW_PARAMETERS = { + "draw_aoi_scene": { + "draw_aoi": { + "color": (255, 255, 255), + "border_size": 1 + } + }, + "draw_aoi_matching": { + "draw_matched_fixation": { + "deviation_circle_color": (255, 255, 255) + }, + "draw_matched_fixation_positions": { + "position_color": (0, 255, 255), + "line_color": (0, 0, 0) + }, + "draw_matched_region": { + "color": (0, 255, 0), + "border_size": 4 + }, + "draw_looked_aoi": { + "color": (0, 255, 0), + "border_size": 2 + }, + "looked_aoi_name_color": (255, 255, 255), + "looked_aoi_name_offset": (0, -10) + } +} + @dataclass class ArLayer(): """ @@ -78,6 +108,7 @@ class ArLayer(): aoi_scan_path: AOI scan path object aoi_scan_path_analyzers: dictionary of AOI scan path analyzers log: enable aoi scan path analysis logging + draw_parameters: default parameters passed to draw method """ name: str @@ -87,6 +118,7 @@ class ArLayer(): aoi_scan_path: GazeFeatures.AOIScanPath = field(default_factory=GazeFeatures.AOIScanPath) aoi_scan_path_analyzers: dict = field(default_factory=dict) log: bool = field(default=False) + draw_parameters: dict = field(default_factory=DEFAULT_ARLAYER_DRAW_PARAMETERS) def __post_init__(self): @@ -283,6 +315,15 @@ class ArLayer(): new_layer_log = False + # Load image parameters + try: + + new_layer_draw_parameters = layer_data.pop('draw_parameters') + + except KeyError: + + new_layer_draw_parameters = DEFAULT_ARLAYER_DRAW_PARAMETERS + # Create layer return ArLayer(new_layer_name, \ new_aoi_color, \ @@ -290,7 +331,8 @@ class ArLayer(): new_aoi_matcher, \ new_aoi_scan_path, \ new_aoi_scan_path_analyzers, \ - new_layer_log \ + new_layer_log, \ + new_layer_draw_parameters \ ) @classmethod @@ -458,6 +500,11 @@ class ArLayer(): draw_aoi_matching: AOIMatcher.draw parameters (which depends of the loaded aoi matcher module, if None, no aoi matching is drawn) """ + # Use draw_parameters attribute if no parameters + if not draw_aoi_scene and not draw_aoi_matching: + + return self.draw(image, **self.draw_parameters) + # Lock frame exploitation self.__look_lock.acquire() @@ -474,7 +521,7 @@ class ArLayer(): # Unlock frame exploitation self.__look_lock.release() -# Define default ArFrame image_paremeters values +# Define default ArFrame image parameters DEFAULT_ARFRAME_IMAGE_PARAMETERS = { "background_weight": 1., "heatmap_weight": 0.5, @@ -489,35 +536,6 @@ DEFAULT_ARFRAME_IMAGE_PARAMETERS = { }, "deepness": 0 }, - "draw_layers": { - "GrayRectangle": { - "draw_aoi_scene": { - "draw_aoi": { - "color": (255, 255, 255), - "border_size": 1 - } - }, - "draw_aoi_matching": { - "draw_matched_fixation": { - "deviation_circle_color": (255, 255, 255) - }, - "draw_matched_fixation_positions": { - "position_color": (0, 255, 255), - "line_color": (0, 0, 0) - }, - "draw_matched_region": { - "color": (0, 255, 0), - "border_size": 4 - }, - "draw_looked_aoi": { - "color": (0, 255, 0), - "border_size": 2 - }, - "looked_aoi_name_color": (255, 255, 255), - "looked_aoi_name_offset": (0, -10) - } - } - }, "draw_gaze_position": { "color": (0, 255, 255) } @@ -756,7 +774,7 @@ class ArFrame(): new_frame_log = False - # Load frame image parameters + # Load image parameters try: new_frame_image_parameters = frame_data.pop('image_parameters') @@ -997,7 +1015,7 @@ class ArFrame(): draw_gaze_position: GazeFeatures.GazePosition parameters (if None, no gaze position is drawn) """ - # If use image_parameters attribute if no parameters + # Use image_parameters attribute if no parameters if not background_weight and not heatmap_weight and not draw_scan_path and not draw_layers and not draw_gaze_position: return self.image(**self.image_parameters) @@ -1022,15 +1040,22 @@ class ArFrame(): image = cv2.resize(self.heatmap.image, dsize=self.size, interpolation=cv2.INTER_LINEAR) + # Draw black image + else: + + image = numpy.full((self.size[1], self.size[0], 3), 0).astype(numpy.uint8) + # Draw scan path if required if draw_scan_path and self.scan_path != None: self.scan_path.draw(image, **draw_scan_path) - # Draw required layers - for layer_name, draw_layer in draw_layers.items(): + # Draw layers if required + if draw_layers: + + for layer_name, draw_layer in draw_layers.items(): - self.layers[layer_name].draw(image, **draw_layer) + self.layers[layer_name].draw(image, **draw_layer) # Draw current gaze position if required if draw_gaze_position: @@ -1776,7 +1801,7 @@ class ArEnvironment(): draw_detected_markers: ArUcoDetector.draw_detected_markers parameters (If None, detected markers are not drawn) """ - # If use image_parameters attribute if no parameters + # Use image_parameters attribute if no parameters if not draw_detected_markers: return self.image(**self.image_parameters) |