aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoScene.py38
-rw-r--r--src/argaze.test/ArUcoMarkers/utils/scene.obj17
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoScene.py20
3 files changed, 72 insertions, 3 deletions
diff --git a/src/argaze.test/ArUcoMarkers/ArUcoScene.py b/src/argaze.test/ArUcoMarkers/ArUcoScene.py
new file mode 100644
index 0000000..537469e
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/ArUcoScene.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+
+import unittest
+import os
+import math
+
+from argaze.ArUcoMarkers import ArUcoScene
+
+import cv2 as cv
+import numpy
+
+class TestArUcoSceneClass(unittest.TestCase):
+ """Test ArUcoScene class."""
+
+ def test_new(self):
+ """Test ArUcoScene creation."""
+
+ # Edit file path
+ current_directory = os.path.dirname(os.path.abspath(__file__))
+ obj_filepath = os.path.join(current_directory, 'utils/scene.obj')
+
+ # Load file
+ aruco_scene = ArUcoScene.ArUcoScene(1, obj_filepath)
+
+ # Check ArUcoScene creation
+ self.assertEqual(len(aruco_scene.places), 2)
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_scene.identifiers, [0, 1]))
+
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_scene.places['DICT_ARUCO_ORIGINAL#0'].translation, [0.5, 0.5, 0.]))
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_scene.places['DICT_ARUCO_ORIGINAL#0'].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]))
+
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_scene.places['DICT_ARUCO_ORIGINAL#1'].translation, [10.5, 10.5, 0.]))
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_scene.places['DICT_ARUCO_ORIGINAL#1'].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]))
+
+
+if __name__ == '__main__':
+
+ unittest.main() \ No newline at end of file
diff --git a/src/argaze.test/ArUcoMarkers/utils/scene.obj b/src/argaze.test/ArUcoMarkers/utils/scene.obj
new file mode 100644
index 0000000..51c8148
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/utils/scene.obj
@@ -0,0 +1,17 @@
+# .OBJ file for ArUcoScene unitary test
+o DICT_ARUCO_ORIGINAL#0_Marker
+v 0.000000 0.000000 0.000000
+v 1.000000 0.000000 0.000000
+v 0.000000 1.000000 0.000000
+v 1.000000 1.000000 0.000000
+vn 0.0000 0.0000 1.0000
+s off
+f 1//1 2//1 4//1 3//1
+o DICT_ARUCO_ORIGINAL#1_Marker
+v 10.000000 10.000000 0.000000
+v 11.000000 10.000000 0.000000
+v 10.000000 11.000000 0.000000
+v 11.000000 11.000000 0.000000
+vn 0.0000 0.0000 1.0000
+s off
+f 5//2 6//2 8//2 7//2
diff --git a/src/argaze/ArUcoMarkers/ArUcoScene.py b/src/argaze/ArUcoMarkers/ArUcoScene.py
index 63aa136..795bfe4 100644
--- a/src/argaze/ArUcoMarkers/ArUcoScene.py
+++ b/src/argaze/ArUcoMarkers/ArUcoScene.py
@@ -38,14 +38,28 @@ class Place():
class ArUcoScene():
"""Handle group of ArUco markers as one unique spatial entity and estimate its pose."""
- def __init__(self, dictionary: ArUcoMarkersDictionary.ArUcoMarkersDictionary, marker_size: float, data_places: dict | str = None):
+ def __init__(self, marker_size: float, places: dict | str, dictionary: ArUcoMarkersDictionary.ArUcoMarkersDictionary = None):
"""Define scene attributes."""
- self.__dictionary = dictionary
+ # Init expected marker size
self.__marker_size = marker_size
+ # Handle dictionary str or instance
+ if dictionary != None:
+
+ if type(dictionary) == str:
+ self.__dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary(dictionary)
+ elif isinstance(dictionary, ArUcoMarkersDictionary.ArUcoMarkersDictionary):
+ self.__dictionary = dictionary
+ else:
+ raise ValueError(f'dictionary: {dictionary}')
+
+ else:
+
+ self.__dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary()
+
# NEVER USE {} as default function argument
- self.places = data_places
+ self.places = places
@property
def places(self) -> dict: