aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2024-01-30 15:02:23 +0100
committerThéo de la Hogue2024-01-30 15:02:23 +0100
commit40228f20770b18f29c1f51dce8f33ee091eeaef0 (patch)
treef0843e4c3313b66de8b1e9f3ba0b3012c8f5a040
parentc9d22c293cc7d6862125e4653ca195f9b6850d23 (diff)
downloadargaze-40228f20770b18f29c1f51dce8f33ee091eeaef0.zip
argaze-40228f20770b18f29c1f51dce8f33ee091eeaef0.tar.gz
argaze-40228f20770b18f29c1f51dce8f33ee091eeaef0.tar.bz2
argaze-40228f20770b18f29c1f51dce8f33ee091eeaef0.tar.xz
Using PipelineStepObject.from_json method.
-rw-r--r--src/argaze/ArFeatures.py32
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoCamera.py16
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoDetector.py16
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoMarkersGroup.py30
-rw-r--r--src/argaze/DataFeatures.py22
5 files changed, 32 insertions, 84 deletions
diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py
index 7ca399e..0cb1d77 100644
--- a/src/argaze/ArFeatures.py
+++ b/src/argaze/ArFeatures.py
@@ -383,22 +383,6 @@ class ArLayer(DataFeatures.SharedObject, DataFeatures.PipelineStepObject):
**temp_pipeline_step_object_data \
)
- @classmethod
- def from_json(self, json_filepath: str) -> ArLayerType:
- """
- Load attributes from .json file.
-
- Parameters:
- json_filepath: path to json file
- """
-
- with open(json_filepath) as configuration_file:
-
- layer_data = json.load(configuration_file)
- working_directory = os.path.dirname(json_filepath)
-
- return ArLayer.from_dict(layer_data, working_directory)
-
@DataFeatures.PipelineStepMethod
def look(self, timestamp: int|float, gaze_movement: GazeFeatures.GazePosition = GazeFeatures.UnvalidGazePosition()):
"""
@@ -889,22 +873,6 @@ class ArFrame(DataFeatures.SharedObject, DataFeatures.PipelineStepObject):
**temp_pipeline_step_object_data \
)
- @classmethod
- def from_json(self, json_filepath: str) -> ArFrameType:
- """
- Load attributes from .json file.
-
- Parameters:
- json_filepath: path to json file
- """
-
- with open(json_filepath) as configuration_file:
-
- frame_data = json.load(configuration_file)
- working_directory = os.path.dirname(json_filepath)
-
- return ArFrame.from_dict(frame_data, working_directory)
-
@DataFeatures.PipelineStepMethod
def look(self, timestamp: int|float, gaze_position: GazeFeatures.GazePosition = GazeFeatures.UnvalidGazePosition()) -> Iterator[Union[object, type, dict]]:
"""
diff --git a/src/argaze/ArUcoMarkers/ArUcoCamera.py b/src/argaze/ArUcoMarkers/ArUcoCamera.py
index 362e84b..7f30252 100644
--- a/src/argaze/ArUcoMarkers/ArUcoCamera.py
+++ b/src/argaze/ArUcoMarkers/ArUcoCamera.py
@@ -131,22 +131,6 @@ class ArUcoCamera(ArFeatures.ArCamera):
**temp_frame_data \
)
- @classmethod
- def from_json(self, json_filepath: str) -> ArUcoCameraType:
- """
- Load ArUcoCamera from .json file.
-
- Parameters:
- json_filepath: path to json file
- """
-
- with open(json_filepath) as configuration_file:
-
- aruco_camera_data = json.load(configuration_file)
- working_directory = os.path.dirname(json_filepath)
-
- return ArUcoCamera.from_dict(aruco_camera_data, working_directory)
-
@DataFeatures.PipelineStepMethod
def watch(self, timestamp: int|float, image: numpy.array):
"""Detect environment aruco markers from image and project scenes into camera frame.
diff --git a/src/argaze/ArUcoMarkers/ArUcoDetector.py b/src/argaze/ArUcoMarkers/ArUcoDetector.py
index 8c843ae..a04bc8f 100644
--- a/src/argaze/ArUcoMarkers/ArUcoDetector.py
+++ b/src/argaze/ArUcoMarkers/ArUcoDetector.py
@@ -253,22 +253,6 @@ class ArUcoDetector(DataFeatures.PipelineStepObject):
# Create aruco detector
return ArUcoDetector(new_dictionary, new_optic_parameters, new_parameters)
- @classmethod
- def from_json(self, json_filepath: str) -> ArUcoDetectorType:
- """
- Load attributes from .json file.
-
- Parameters:
- json_filepath: path to json file
- """
-
- with open(json_filepath) as configuration_file:
-
- aruco_detector_data = json.load(configuration_file)
- working_directory = os.path.dirname(json_filepath)
-
- return ArUcoDetector.from_dict(aruco_detector_data, working_directory)
-
@DataFeatures.PipelineStepMethod
def detect_markers(self, timestamp: int|float, image: numpy.array) -> float:
"""Detect all ArUco markers into an image.
diff --git a/src/argaze/ArUcoMarkers/ArUcoMarkersGroup.py b/src/argaze/ArUcoMarkers/ArUcoMarkersGroup.py
index 2fd7eee..f587c59 100644
--- a/src/argaze/ArUcoMarkers/ArUcoMarkersGroup.py
+++ b/src/argaze/ArUcoMarkers/ArUcoMarkersGroup.py
@@ -191,6 +191,20 @@ class ArUcoMarkersGroup(DataFeatures.PipelineStepObject):
"dictionary": self.__dictionary,
"places": self.__places
}
+
+ @classmethod
+ def from_dict(cls, aruco_markers_group_data: dict, working_directory: str = None) -> ArUcoMarkersGroupType:
+ """Load ArUco markers group attributes from dictionary.
+
+ Parameters:
+ aruco_markers_group_data: dictionary with attributes to load
+ working_directory: folder path where to load files when a dictionary value is a relative filepath.
+ """
+
+ new_dictionary = data.pop('dictionary')
+ new_places = data.pop('places')
+
+ return ArUcoMarkersGroup(new_dictionary, new_places)
@classmethod
def from_obj(self, obj_filepath: str) -> ArUcoMarkersGroupType:
@@ -310,22 +324,6 @@ class ArUcoMarkersGroup(DataFeatures.PipelineStepObject):
return ArUcoMarkersGroup(new_dictionary, new_places)
- @classmethod
- def from_json(self, json_filepath: str) -> ArUcoMarkersGroupType:
- """Load ArUco markers group from .json file."""
-
- new_dictionary = None
- new_places = {}
-
- with open(json_filepath) as configuration_file:
-
- data = json.load(configuration_file)
-
- new_dictionary = data.pop('dictionary')
- new_places = data.pop('places')
-
- return ArUcoMarkersGroup(new_dictionary, new_places)
-
def filter_markers(self, detected_markers: dict) -> Tuple[dict, dict]:
"""Sort markers belonging to the group from given detected markers dict (cf ArUcoDetector.detect_markers()).
diff --git a/src/argaze/DataFeatures.py b/src/argaze/DataFeatures.py
index 6c77c37..06201fe 100644
--- a/src/argaze/DataFeatures.py
+++ b/src/argaze/DataFeatures.py
@@ -521,14 +521,28 @@ class PipelineStepObject():
)
@classmethod
- def from_json(self, json_filepath: str) -> object:
+ def from_json(cls, configuration_filepath: str, patch_filepath: str = None) -> object:
"""
- Define abstract method to load pipeline step object from .json file.
+ Load pipeline step object from .json file.
Parameters:
- json_filepath: path to json file
+ configuration_filepath: path to json configuration file
+ patch_filepath: path to json patch file to modify any configuration entries
"""
- raise NotImplementedError('from_json() method not implemented')
+ with open(configuration_filepath) as configuration_file:
+
+ object_data = json.load(configuration_file)
+ working_directory = os.path.dirname(configuration_filepath)
+
+ # Apply patch to configuration if required
+ if patch_filepath is not None:
+
+ with open(patch_filepath) as patch_file:
+
+ patch_data = json.load(patch_file)
+ object_data.update(patch_data)
+
+ return cls.from_dict(object_data, working_directory)
def to_json(self, json_filepath: str = None):
"""Save pipeline step object into .json file."""