diff options
author | Théo de la Hogue | 2023-08-30 16:41:22 +0200 |
---|---|---|
committer | Théo de la Hogue | 2023-08-30 16:41:22 +0200 |
commit | 3be9a7dc5a083d9476cac30128340f2bd4e0ceb0 (patch) | |
tree | 4844fe8ab8aceb45796d759e405efa7faab4deb8 /src | |
parent | 53d12ee867cc545fc804a1549b692dd5ab6a9387 (diff) | |
download | argaze-3be9a7dc5a083d9476cac30128340f2bd4e0ceb0.zip argaze-3be9a7dc5a083d9476cac30128340f2bd4e0ceb0.tar.gz argaze-3be9a7dc5a083d9476cac30128340f2bd4e0ceb0.tar.bz2 argaze-3be9a7dc5a083d9476cac30128340f2bd4e0ceb0.tar.xz |
Fixing ArEnvironment drawing.
Diffstat (limited to 'src')
-rw-r--r-- | src/argaze/ArFeatures.py | 78 |
1 files changed, 54 insertions, 24 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py index 1d6bf84..1e633ca 100644 --- a/src/argaze/ArFeatures.py +++ b/src/argaze/ArFeatures.py @@ -467,7 +467,7 @@ class ArLayer(): self.aoi_scene.draw(image, **draw_aoi_scene) # Draw aoi matching if required - if draw_aoi_matching: + if draw_aoi_matching and self.aoi_matcher: self.aoi_matcher.draw(image, **draw_aoi_matching) @@ -1414,6 +1414,11 @@ class ArScene(): self.aruco_scene.draw_places(image, self.parent.aruco_detector.optic_parameters.K, self.parent.aruco_detector.optic_parameters.D) +# Define default ArEnvironment image_paremeters values +DEFAULT_ARENVIRONMENT_IMAGE_PARAMETERS = { + "draw_detected_markers": True +} + @dataclass class ArEnvironment(): """ @@ -1430,6 +1435,7 @@ class ArEnvironment(): aruco_detector: ArUcoDetector.ArUcoDetector = field(default_factory=ArUcoDetector.ArUcoDetector) camera_frame: ArFrame = field(default_factory=ArFrame) scenes: dict = field(default_factory=dict) + image_parameters: dict = field(default_factory=DEFAULT_ARENVIRONMENT_IMAGE_PARAMETERS) def __post_init__(self): @@ -1547,8 +1553,22 @@ class ArEnvironment(): camera_frame_layer.aoi_scan_path.expected_aois = all_aoi_list + # Load environment image parameters + try: + + new_environment_image_parameters = environment_data.pop('image_parameters') + + except KeyError: + + new_environment_image_parameters = DEFAULT_ARENVIRONMENT_IMAGE_PARAMETERS + # Create new environment - return ArEnvironment(new_environment_name, new_aruco_detector, new_camera_frame, new_scenes) + return ArEnvironment(new_environment_name, \ + new_aruco_detector, \ + new_camera_frame, \ + new_scenes, \ + new_environment_image_parameters \ + ) @classmethod def from_json(self, json_filepath: str) -> ArEnvironmentType: @@ -1581,28 +1601,6 @@ class ArEnvironment(): return output @property - def image(self): - """Get camera frame projections with ArUco detection visualisation.""" - - # Can't use camera frame when it is locked - if self.__camera_frame_lock.locked(): - return - - # Lock camera frame exploitation - self.__camera_frame_lock.acquire() - - # Get camera frame image - image = self.camera_frame.image - - # Draw detected markers - self.aruco_detector.draw_detected_markers(image) - - # Unlock camera frame exploitation - self.__camera_frame_lock.release() - - return image - - @property def frames(self): """Iterate over all environment scenes frames""" @@ -1771,6 +1769,38 @@ class ArEnvironment(): # Unlock camera frame exploitation self.__camera_frame_lock.release() + def image(self, draw_detected_markers: dict = None): + """Get camera frame projections with ArUco detection visualisation. + + Parameters: + draw_detected_markers: ArUcoDetector.draw_detected_markers parameters (If None, detected markers are not drawn) + """ + + # If use image_parameters attribute if no parameters + if not draw_detected_markers: + + return self.image(**self.image_parameters) + + # Can't use camera frame when it is locked + if self.__camera_frame_lock.locked(): + return + + # Lock camera frame exploitation + self.__camera_frame_lock.acquire() + + # Get camera frame image + image = self.camera_frame.image() + + # Draw detected markers if required + if draw_detected_markers: + + self.aruco_detector.draw_detected_markers(image) + + # Unlock camera frame exploitation + self.__camera_frame_lock.release() + + return image + def to_json(self, json_filepath): """Save environment to .json file.""" |