diff options
-rw-r--r-- | src/argaze/ArFeatures.py | 46 | ||||
-rw-r--r-- | src/argaze/ArUcoMarkers/ArUcoDetector.py | 8 | ||||
-rw-r--r-- | src/argaze/ArUcoMarkers/ArUcoMarkersDictionary.py | 7 | ||||
-rw-r--r-- | src/argaze/ArUcoMarkers/ArUcoScene.py | 4 |
4 files changed, 47 insertions, 18 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py index a684fc6..6247482 100644 --- a/src/argaze/ArFeatures.py +++ b/src/argaze/ArFeatures.py @@ -35,6 +35,13 @@ class ArEnvironment(): scenes: dict = field(default_factory=dict) """All environment scenes""" + def __post_init__(self): + + # Setup scenes environment after environment creation + for name, scene in self.scenes.items(): + + scene.environment = self + @classmethod def from_json(self, json_filepath: str) -> ArSceneType: """Load ArEnvironment from .json file.""" @@ -49,9 +56,22 @@ class ArEnvironment(): new_aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(new_detector_data.pop('dictionary')) new_marker_size = new_detector_data.pop('marker_size') - new_aruco_camera = ArUcoCamera.ArUcoCamera(**new_detector_data.pop('camera')) - new_aruco_detecor_parameters = ArUcoDetector.DetectorParameters(**new_detector_data.pop('parameters')) + # Check aruco_camera value type + aruco_camera_value = new_detector_data.pop('camera') + + # str: relative path to .json file + if type(aruco_camera_value) == str: + + aruco_camera_value = os.path.join(new_working_directory, aruco_camera_value) + new_aruco_camera = ArUcoCamera.ArUcoCamera.from_json(aruco_camera_value) + + # dict: + else: + + new_aruco_camera = ArUcoCamera.ArUcoCamera(**aruco_camera_value) + + new_aruco_detecor_parameters = ArUcoDetector.DetectorParameters(**new_detector_data.pop('parameters')) new_aruco_detector = ArUcoDetector.ArUcoDetector(new_aruco_dictionary, new_marker_size, new_aruco_camera, new_aruco_detecor_parameters) for scene_name, scene_data in data.items(): @@ -88,16 +108,17 @@ class ArEnvironment(): new_aoi_scene = AOI3DScene.AOI3DScene(aoi_scene_value) - new_scenes[scene_name] = ArScene(self, new_aruco_scene, new_aoi_scene, **scene_data) + new_scenes[scene_name] = ArScene(new_aruco_scene, new_aoi_scene, **scene_data) return ArEnvironment(new_name, new_working_directory, new_aruco_detector, new_scenes) def __str__(self) -> str: """String display""" - output = f'ArUcoDetector:\n{self.aruco_detector}\n' + output = f'Name:\n{self.name}\n' + output += f'ArUcoDetector:\n{self.aruco_detector}\n' - for name, scene in self.__scenes.items(): + for name, scene in self.scenes.items(): output += f'\"{name}\" ArScene:\n{scene}\n' return output @@ -122,9 +143,6 @@ class SceneProjectionFailed(Exception): class ArScene(): """Define an Augmented Reality scene with ArUco markers and AOI scenes.""" - ar_environment: ArEnvironment = field(default_factory=ArEnvironment) - """AR Environment to which the scene belongs.""" - aruco_scene: ArUcoScene.ArUcoScene = field(default_factory=ArUcoScene.ArUcoScene) """ArUco markers 3D scene description used to estimate scene pose from detected markers: see `estimate_pose` function below.""" @@ -146,13 +164,17 @@ class ArScene(): def __post_init__(self): + # Define environment attribute: it will be setup by parent environment later + self.environment = None + # Preprocess orthogonal projection to speed up further aruco aoi processings self.__orthogonal_projection_cache = self.orthogonal_projection def __str__(self) -> str: """String display""" - output = f'ArUcoScene:\n{self.aruco_scene}\n' + output = f'ArEnvironment:\n{self.environment.name}\n' + output += f'ArUcoScene:\n{self.aruco_scene}\n' output += f'AOIScene:\n{self.aoi_scene}\n' return output @@ -262,7 +284,7 @@ class ArScene(): aoi_scene_copy = self.aoi_scene.copy() - aoi_scene_projection = aoi_scene_copy.project(tvec, rvec, self.ar_environment.aruco_detector.camera.K) + aoi_scene_projection = aoi_scene_copy.project(tvec, rvec, self.environment.aruco_detector.camera.K) # Warn user when the projected scene is empty if len(aoi_scene_projection) == 0: @@ -312,11 +334,11 @@ class ArScene(): def draw_axis(self, frame): """Draw scene axis into frame.""" - self.aruco_scene.draw_axis(frame, self.ar_environment.aruco_detector.camera.K, self.ar_environment.aruco_detector.camera.D) + self.aruco_scene.draw_axis(frame, self.environment.aruco_detector.camera.K, self.environment.aruco_detector.camera.D) def draw_places(self, frame): """Draw scene places into frame.""" - self.aruco_scene.draw_places(frame, self.ar_environment.aruco_detector.camera.K, self.ar_environment.aruco_detector.camera.D) + self.aruco_scene.draw_places(frame, self.environment.aruco_detector.camera.K, self.environment.aruco_detector.camera.D) diff --git a/src/argaze/ArUcoMarkers/ArUcoDetector.py b/src/argaze/ArUcoMarkers/ArUcoDetector.py index d96a472..333df7b 100644 --- a/src/argaze/ArUcoMarkers/ArUcoDetector.py +++ b/src/argaze/ArUcoMarkers/ArUcoDetector.py @@ -161,10 +161,10 @@ class ArUcoDetector(): def __str__(self) -> str: """String display""" - output = f'Dictionary:\n{self.dictionary}\n' - output += f'Marker size:\n{self.marker_size}\n' - output += f'Camera:\n{self.camera}\n' - output += f'Parameters:\n{self.parameters}\n' + output = f'\n\tDictionary: {self.dictionary}\n' + output += f'\tMarker size: {self.marker_size} cm\n\n' + output += f'\tCamera:\n{self.camera}\n' + output += f'\tParameters:\n{self.parameters}' return output diff --git a/src/argaze/ArUcoMarkers/ArUcoMarkersDictionary.py b/src/argaze/ArUcoMarkers/ArUcoMarkersDictionary.py index 8599293..8c43844 100644 --- a/src/argaze/ArUcoMarkers/ArUcoMarkersDictionary.py +++ b/src/argaze/ArUcoMarkers/ArUcoMarkersDictionary.py @@ -85,6 +85,13 @@ class ArUcoMarkersDictionary(): self.__number = int(dict_name_split[2]) self.__aruco_dict = aruco.getPredefinedDictionary(all_aruco_markers_dictionaries[self.__name]) + + def __str__(self) -> str: + """String display""" + + output = f'{self.__name}\n' + + return output @property def name(self)-> str: diff --git a/src/argaze/ArUcoMarkers/ArUcoScene.py b/src/argaze/ArUcoMarkers/ArUcoScene.py index 19fcf07..06faa41 100644 --- a/src/argaze/ArUcoMarkers/ArUcoScene.py +++ b/src/argaze/ArUcoMarkers/ArUcoScene.py @@ -316,9 +316,9 @@ class ArUcoScene(): def __str__(self) -> str: """String display""" - output = f'\n\n\tDictionary: {self.dictionary.name}' + output = f'\n\tDictionary: {self.dictionary}' - output = f'\n\n\tMarker size: {self.marker_size} cm' + output += f'\n\tMarker size: {self.marker_size} cm' output += '\n\n\tPlaces:' for identifier, place in self.places.items(): |