aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/user_guide/aruco_markers_pipeline/aruco_camera_configuration_and_execution.md28
-rw-r--r--docs/user_guide/aruco_markers_pipeline/aruco_scene.md56
-rw-r--r--docs/user_guide/aruco_markers_pipeline/introduction.md4
-rw-r--r--docs/user_guide/gaze_analysis_pipeline/ar_frame_configuration_and_execution.md4
-rw-r--r--docs/user_guide/gaze_analysis_pipeline/ar_layer.md7
-rw-r--r--mkdocs.yml1
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoCamera.py42
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoDetector.py81
8 files changed, 147 insertions, 76 deletions
diff --git a/docs/user_guide/aruco_markers_pipeline/aruco_camera_configuration_and_execution.md b/docs/user_guide/aruco_markers_pipeline/aruco_camera_configuration_and_execution.md
index 9b1db42..7b30fd1 100644
--- a/docs/user_guide/aruco_markers_pipeline/aruco_camera_configuration_and_execution.md
+++ b/docs/user_guide/aruco_markers_pipeline/aruco_camera_configuration_and_execution.md
@@ -3,7 +3,7 @@ Configure and execute ArUcoCamera
Once [ArUco markers are placed into a scene](aruco_scene_creation.md) and [the camera optic have been calibrated](optic_parameters_calibration.md), everything is ready to setup an ArUco marker pipeline thanks to [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) class.
-As it inherits from [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame), the [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) class benefits from all the services of a [gaze analysis pipeline](./user_guide/gaze_analysis_pipeline/introduction.md). Besides, the [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) class projects [ArUcoScenes](../../argaze.md/#argaze.ArUcoMarkers.ArUcoScene)'s layers into its own layers thanks to ArUco markers pose estimations made by its [ArUcoDetector](../../argaze.md/#argaze.ArUcoMarkers.ArUcoDetector).
+As it inherits from [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame), the [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) class benefits from all the services described in [gaze analysis pipeline section](./user_guide/gaze_analysis_pipeline/introduction.md).
![ArUco camera frame](../../img/aruco_camera_frame.png)
@@ -11,24 +11,17 @@ As it inherits from [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame), the [
The [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) internal pipeline loads from a JSON configuration file thanks to [ArUcoCamera.from_json](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera.from_json) class method.
-Here is a simple JSON ArUcoCamera configuration file example:
+Here is a simple JSON [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) configuration file example:
```json
{
"name": "My FullHD camera",
"size": [1920, 1080],
"aruco_detector": {
- "dictionary": {
- "name": "DICT_APRILTAG_16h5"
- },
+ "dictionary": "DICT_APRILTAG_16h5",
"marker_size": 5,
"optic_parameters": "optic_parameters.json",
},
- "scenes": {
- "main_scene" : {
- "aruco_markers_group": "aruco_description.json"
- }
- },
"image_parameters": {
"background_weight": 1,
"draw_detected_markers": {
@@ -52,21 +45,22 @@ aruco_camera = ArUcoCamera.ArUcoCamera.from_json('./configuration.json')
Now, let's understand the meaning of each JSON entry.
-### Name (inherited from ArFrame)
+### Name - *inherited from [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame)*
The name of the [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) frame. Basically useful for visualisation purpose.
-### Size (inherited from ArFrame)
+### Size - *inherited from [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame)*
-The size of the [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) frame in pixels. Be aware that gaze positions have to be in the same range of value.
+The size of the [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) frame in pixels. Be aware that gaze positions have to be in the same range of value to be projected in.
-### ArUco detector
+### ArUco Detector
-...
+The first [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) pipeline step is to detect ArUco markers inside input image.
-### Scenes
+The [ArUcoDetector](../../argaze.md/#argaze.ArUcoMarkers.ArUcoDetector) is in charge to detect ...
-...
+!!! warning
+ JSON *aruco_detector* entry is mandatory.
### Image parameters (inherited from ArFrame)
diff --git a/docs/user_guide/aruco_markers_pipeline/aruco_scene.md b/docs/user_guide/aruco_markers_pipeline/aruco_scene.md
new file mode 100644
index 0000000..2f37fa7
--- /dev/null
+++ b/docs/user_guide/aruco_markers_pipeline/aruco_scene.md
@@ -0,0 +1,56 @@
+Add an ArUcoScene
+=================
+
+An [ArUcoScene](../../argaze.md/#argaze.ArUcoMarkers.ArUcoScene) class defines ...
+
+Besides, the [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) class projects [ArUcoScenes](../../argaze.md/#argaze.ArUcoMarkers.ArUcoScene)'s layers into its own layers thanks to ArUco markers pose estimations made by its [ArUcoDetector](../../argaze.md/#argaze.ArUcoMarkers.ArUcoDetector).
+
+![ArUco scene](../../img/aruco_scene.png)
+
+## Add ArUcoScene to ArUcoCamera JSON configuration file
+
+An [ArUcoCamera](../../argaze.md/#argaze.ArUcoMarkers.ArUcoCamera) instance can contains multiples [ArUcoScene](../../argaze.md/#argaze.ArUcoMarkers.ArUcoScene).
+
+Here is an extract from the JSON ArUcoCamera configuration file with a sample where one scene is added:
+
+```json
+{
+ "name": "My FullHD camera",
+ "size": [1920, 1080],
+ ...
+ "scenes": {
+ "MyScene" : {
+ "aruco_markers_group": "aruco_description.json"
+ },
+ "layers": {
+ "MyLayer": {
+ "aoi_scene": "aoi_description.obj"
+ }
+ }
+ },
+ "layers": {
+ "MyLayer": {}
+ }
+ ...
+}
+```
+
+Now, let's understand the meaning of each JSON entry.
+
+### "MyLayer"
+
+The name of the [ArUcoScene](../../argaze.md/#argaze.ArUcoMarkers.ArUcoScene). Basically useful for visualisation purpose.
+
+### ArUco markers group
+
+...
+
+### Layers
+
+...
+
+### AOI scene
+
+The [AOIScene](../../argaze.md/#argaze.AreaOfInterest.AOIFeatures.AOIScene) defines a set of 2D [AreaOfInterest](../../argaze.md/#argaze.AreaOfInterest.AOIFeatures.AreaOfInterest) registered by name.
+
+![AOI Scene](../../img/ar_layer_aoi_scene.png)
diff --git a/docs/user_guide/aruco_markers_pipeline/introduction.md b/docs/user_guide/aruco_markers_pipeline/introduction.md
index ae174f3..77b93a2 100644
--- a/docs/user_guide/aruco_markers_pipeline/introduction.md
+++ b/docs/user_guide/aruco_markers_pipeline/introduction.md
@@ -18,8 +18,8 @@ To build your own ArUco markers pipeline, you need to know:
* [How to setup ArUco markers into a scene](aruco_markers_description.md),
* [How to calibrate optic parameters](optic_parameters_calibration.md),
* [How to deal with an ArUcoCamera instance](aruco_camera_configuration_and_execution.md),
-* [How to add ArScene instance](ar_scene.md),
-* [How to visualize ArCamera and ArScenes](visualisation.md)
+* [How to add ArLayer instance](ar_layer.md),
+* [How to visualize ArUcoCamera and ArLayers](visualisation.md)
More advanced features are also explained like:
diff --git a/docs/user_guide/gaze_analysis_pipeline/ar_frame_configuration_and_execution.md b/docs/user_guide/gaze_analysis_pipeline/ar_frame_configuration_and_execution.md
index cdc7fe0..d649a4b 100644
--- a/docs/user_guide/gaze_analysis_pipeline/ar_frame_configuration_and_execution.md
+++ b/docs/user_guide/gaze_analysis_pipeline/ar_frame_configuration_and_execution.md
@@ -9,7 +9,7 @@ The [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame) class defines a rectan
The [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame) internal pipeline is entirely customizable from a JSON configuration file thanks to [ArFrame.from_json](../../argaze.md/#argaze.ArFeatures.ArFrame.from_json) class method.
-Here is a simple JSON ArFrame configuration file example:
+Here is a simple JSON [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame) configuration file example:
```json
{
@@ -50,7 +50,7 @@ The name of the [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame). Basically
### Size
-The size of the [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame) defines the dimension of the rectangular area where gaze positions are projected. Be aware that gaze positions have to be in the same range of value.
+The size of the [ArFrame](../../argaze.md/#argaze.ArFeatures.ArFrame) defines the dimension of the rectangular area where gaze positions are projected. Be aware that gaze positions have to be in the same range of value to be projected in.
!!! warning
**ArGaze doesn't impose any spatial unit.** Gaze positions can either be integer or float, pixels, millimeters or what ever you need. The only concern is that all spatial values used in further configurations have to be all the same unit.
diff --git a/docs/user_guide/gaze_analysis_pipeline/ar_layer.md b/docs/user_guide/gaze_analysis_pipeline/ar_layer.md
index 893e50c..9261e97 100644
--- a/docs/user_guide/gaze_analysis_pipeline/ar_layer.md
+++ b/docs/user_guide/gaze_analysis_pipeline/ar_layer.md
@@ -18,7 +18,6 @@ Here is an extract from the JSON ArFrame configuration file with a sample where
...
"layers": {
"MyLayer": {
- "aoi_color": [0, 0, 255],
"aoi_scene" : {
"upper_left_area": [[0, 0], [960, 0], [960, 540], [0, 540]],
"upper_right_area": [[960, 0], [1920, 0], [1920, 540], [960, 540]],
@@ -52,14 +51,10 @@ Here is an extract from the JSON ArFrame configuration file with a sample where
Now, let's understand the meaning of each JSON entry.
-### Name
+### "MyLayer"
The name of the [ArLayer](../../argaze.md/#argaze.ArFeatures.ArLayer). Basically useful for visualisation purpose.
-### AOI Color
-
-The color of [ArLayer](../../argaze.md/#argaze.ArFeatures.ArLayer)'s AOI. Basically useful for visualisation purpose.
-
### AOI Scene
The [AOIScene](../../argaze.md/#argaze.AreaOfInterest.AOIFeatures.AOIScene) defines a set of 2D [AreaOfInterest](../../argaze.md/#argaze.AreaOfInterest.AOIFeatures.AreaOfInterest) registered by name.
diff --git a/mkdocs.yml b/mkdocs.yml
index 0755961..6347224 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -26,6 +26,7 @@ nav:
- user_guide/aruco_markers_pipeline/aruco_markers_description.md
- user_guide/aruco_markers_pipeline/optic_parameters_calibration.md
- user_guide/aruco_markers_pipeline/aruco_camera_configuration_and_execution.md
+ - user_guide/aruco_markers_pipeline/aruco_scene.md
# - ArUco Markers:
# - user_guide/aruco_markers/introduction.md
# - user_guide/aruco_markers/dictionary_selection.md
diff --git a/src/argaze/ArUcoMarkers/ArUcoCamera.py b/src/argaze/ArUcoMarkers/ArUcoCamera.py
index 30b4415..134e76b 100644
--- a/src/argaze/ArUcoMarkers/ArUcoCamera.py
+++ b/src/argaze/ArUcoMarkers/ArUcoCamera.py
@@ -71,47 +71,7 @@ class ArUcoCamera(ArFeatures.ArCamera):
"""
# Load ArUco detector
- new_detector_data = aruco_camera_data.pop('aruco_detector')
-
- new_aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(**new_detector_data.pop('dictionary'))
- new_marker_size = new_detector_data.pop('marker_size')
-
- # Check optic_parameters value type
- optic_parameters_value = new_detector_data.pop('optic_parameters')
-
- # str: relative path to .json file
- if type(optic_parameters_value) == str:
-
- optic_parameters_value = os.path.join(working_directory, optic_parameters_value)
- new_optic_parameters = ArUcoOpticCalibrator.OpticParameters.from_json(optic_parameters_value)
-
- # dict:
- else:
-
- new_optic_parameters = ArUcoOpticCalibrator.OpticParameters(**optic_parameters_value)
-
- # Load ArUco detector parameters
- try:
-
- # Check detector parameters value type
- detector_parameters_value = new_detector_data.pop('parameters')
-
- # str: relative path to .json file
- if type(detector_parameters_value) == str:
-
- detector_parameters_value = os.path.join(working_directory, detector_parameters_value)
- new_aruco_detector_parameters = ArUcoDetector.DetectorParameters.from_json(detector_parameters_value)
-
- # dict:
- else:
-
- new_aruco_detector_parameters = ArUcoDetector.DetectorParameters(**detector_parameters_value)
-
- except KeyError:
-
- new_aruco_detector_parameters = ArUcoDetector.DetectorParameters()
-
- new_aruco_detector = ArUcoDetector.ArUcoDetector(new_aruco_dictionary, new_marker_size, new_optic_parameters, new_aruco_detector_parameters)
+ new_aruco_detector = ArUcoDetector.ArUcoDetector.from_dict(aruco_camera_data.pop('aruco_detector'), working_directory)
# Load ArUcoScenes
new_scenes = {}
diff --git a/src/argaze/ArUcoMarkers/ArUcoDetector.py b/src/argaze/ArUcoMarkers/ArUcoDetector.py
index 135eb08..73bea88 100644
--- a/src/argaze/ArUcoMarkers/ArUcoDetector.py
+++ b/src/argaze/ArUcoMarkers/ArUcoDetector.py
@@ -10,6 +10,7 @@ __license__ = "BSD"
from typing import TypeVar, Tuple
from dataclasses import dataclass, field
import json
+import os
from collections import Counter
import time
@@ -152,19 +153,83 @@ class ArUcoDetector():
self.__detected_ids = []
@classmethod
+ def from_dict(self, aruco_detector_data: dict, working_directory: str = None) -> ArUcoDetectorType:
+ """Load attributes from dictionary.
+
+ Parameters:
+ aruco_detector_data: dictionary with attributes to load
+ working_directory: folder path where to load files when a dictionary value is a relative filepath.
+ """
+
+ # Load ArUco dictionary
+ dictionary_value = aruco_detector_data.pop('dictionary')
+
+ # str: dictionary name
+ if type(dictionary_value) == str:
+
+ new_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(dictionary_value)
+
+ # dict:
+ else:
+
+ new_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(**dictionary_value)
+
+ # Load ArUco marker size
+ new_marker_size = aruco_detector_data.pop('marker_size')
+
+ # Load optic_parameters value type
+ optic_parameters_value = aruco_detector_data.pop('optic_parameters')
+
+ # str: relative path to .json file
+ if type(optic_parameters_value) == str:
+
+ optic_parameters_value = os.path.join(working_directory, optic_parameters_value)
+ new_optic_parameters = ArUcoOpticCalibrator.OpticParameters.from_json(optic_parameters_value)
+
+ # dict:
+ else:
+
+ new_optic_parameters = ArUcoOpticCalibrator.OpticParameters(**optic_parameters_value)
+
+ # Load ArUco detector parameters
+ try:
+
+ # Check detector parameters value type
+ parameters_value = aruco_detector_data.pop('parameters')
+
+ # str: relative path to .json file
+ if type(parameters_value) == str:
+
+ parameters_value = os.path.join(working_directory, parameters_value)
+ new_parameters = DetectorParameters.from_json(parameters_value)
+
+ # dict:
+ else:
+
+ new_parameters = DetectorParameters(**parameters_value)
+
+ except KeyError:
+
+ new_parameters = DetectorParameters()
+
+ # Create aruco detector
+ return ArUcoDetector(new_dictionary, new_marker_size, new_optic_parameters, new_parameters)
+
+ @classmethod
def from_json(self, json_filepath: str) -> ArUcoDetectorType:
- """Load ArUcoDetector setup from .json file."""
+ """
+ Load attributes from .json file.
- with open(json_filepath) as configuration_file:
+ Parameters:
+ json_filepath: path to json file
+ """
- data = json.load(configuration_file)
+ with open(json_filepath) as configuration_file:
- new_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(**data.pop('dictionary'))
- new_marker_size = data.pop('marker_size')
- new_optic_parameters = ArUcoOpticCalibrator.OpticParameters(**data.pop('optic_parameters'))
- new_parameters = DetectorParameters(**data.pop('parameters'))
+ aruco_detector_data = json.load(configuration_file)
+ working_directory = os.path.dirname(json_filepath)
- return ArUcoDetector(new_dictionary, new_marker_size, new_optic_parameters, new_parameters)
+ return ArUcoDetector.from_dict(aruco_detector_data, working_directory)
def __str__(self) -> str:
"""String display"""