aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThéo de la Hogue2023-04-12 11:16:01 +0200
committerThéo de la Hogue2023-04-12 11:16:01 +0200
commitceca96db817c948a7e347821feef4953ac2888cc (patch)
tree416ab226b97511b39f0ec3bcd7e217a069864d4f /src
parentbad9e4104e816c2c7d7b84afd6dfe70cee1f41d1 (diff)
downloadargaze-ceca96db817c948a7e347821feef4953ac2888cc.zip
argaze-ceca96db817c948a7e347821feef4953ac2888cc.tar.gz
argaze-ceca96db817c948a7e347821feef4953ac2888cc.tar.bz2
argaze-ceca96db817c948a7e347821feef4953ac2888cc.tar.xz
Remvoving working directory attribute. Updating ArUcoMarkerDictionary loading. Removing useless print.
Diffstat (limited to 'src')
-rw-r--r--src/argaze/ArFeatures.py38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py
index 2d5b62d..467aa03 100644
--- a/src/argaze/ArFeatures.py
+++ b/src/argaze/ArFeatures.py
@@ -5,6 +5,7 @@ from dataclasses import dataclass, field
import json
import os
+from argaze import DataStructures
from argaze.ArUcoMarkers import *
from argaze.AreaOfInterest import *
@@ -26,9 +27,6 @@ class ArEnvironment():
name: str
"""Environment name"""
- working_directory: str
- """Environment working directory"""
-
aruco_detector: ArUcoDetector.ArUcoDetector = field(default_factory=ArUcoDetector.ArUcoDetector)
"""ArUco detector"""
@@ -39,10 +37,7 @@ class ArEnvironment():
# Setup scenes environment after environment creation
for name, scene in self.scenes.items():
-
- print(name)
-
- scene.environment = self
+ scene._environment = self
@classmethod
def from_json(self, json_filepath: str) -> ArSceneType:
@@ -51,12 +46,12 @@ class ArEnvironment():
with open(json_filepath) as configuration_file:
data = json.load(configuration_file)
+ working_directory = os.path.dirname(json_filepath)
new_name = data.pop('name')
- new_working_directory = os.path.dirname(json_filepath)
new_detector_data = data.pop('aruco_detector')
- new_aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(new_detector_data.pop('dictionary'))
+ new_aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(**new_detector_data.pop('dictionary'))
new_marker_size = new_detector_data.pop('marker_size')
# Check aruco_camera value type
@@ -65,7 +60,7 @@ class ArEnvironment():
# str: relative path to .json file
if type(aruco_camera_value) == str:
- aruco_camera_value = os.path.join(new_working_directory, aruco_camera_value)
+ aruco_camera_value = os.path.join(working_directory, aruco_camera_value)
new_aruco_camera = ArUcoCamera.ArUcoCamera.from_json(aruco_camera_value)
# dict:
@@ -88,7 +83,7 @@ class ArEnvironment():
# str: relative path to .obj file
if type(aruco_scene_value) == str:
- aruco_scene_value = os.path.join(new_working_directory, aruco_scene_value)
+ aruco_scene_value = os.path.join(working_directory, aruco_scene_value)
new_aruco_scene = ArUcoScene.ArUcoScene.from_obj(aruco_scene_value)
# dict:
@@ -102,7 +97,7 @@ class ArEnvironment():
# str: relative path to .obj file
if type(aoi_scene_value) == str:
- obj_filepath = os.path.join(new_working_directory, aoi_scene_value)
+ obj_filepath = os.path.join(working_directory, aoi_scene_value)
new_aoi_scene = AOI3DScene.AOI3DScene.from_obj(obj_filepath)
# dict:
@@ -112,7 +107,7 @@ class ArEnvironment():
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)
+ return ArEnvironment(new_name, new_aruco_detector, new_scenes)
def __str__(self) -> str:
"""String display"""
@@ -125,6 +120,13 @@ class ArEnvironment():
return output
+ def to_json(self, json_filepath):
+ """Save environment to .json file."""
+
+ with open(json_filepath, 'w', encoding='utf-8') as file:
+
+ json.dump(self, file, ensure_ascii=False, indent=4, cls=DataStructures.JsonEncoder)
+
class PoseEstimationFailed(Exception):
"""Exception raised by ArScene estimate_pose method when the pose can't be estimated due to unconsistencies."""
@@ -167,7 +169,7 @@ class ArScene():
def __post_init__(self):
# Define environment attribute: it will be setup by parent environment later
- self.environment = None
+ self._environment = None
# Preprocess orthogonal projection to speed up further aruco aoi processings
self.__orthogonal_projection_cache = self.orthogonal_projection
@@ -175,7 +177,7 @@ class ArScene():
def __str__(self) -> str:
"""String display"""
- output = f'ArEnvironment:\n{self.environment.name}\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'
@@ -286,7 +288,7 @@ class ArScene():
aoi_scene_copy = self.aoi_scene.copy()
- aoi_scene_projection = aoi_scene_copy.project(tvec, rvec, self.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:
@@ -336,11 +338,11 @@ class ArScene():
def draw_axis(self, frame):
"""Draw scene axis into frame."""
- self.aruco_scene.draw_axis(frame, self.environment.aruco_detector.camera.K, self.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.environment.aruco_detector.camera.K, self.environment.aruco_detector.camera.D)
+ self.aruco_scene.draw_places(frame, self._environment.aruco_detector.camera.K, self._environment.aruco_detector.camera.D)