diff options
Diffstat (limited to 'src/argaze.test')
-rw-r--r-- | src/argaze.test/ArFeatures.py | 75 | ||||
-rw-r--r-- | src/argaze.test/ArUcoMarkers/ArUcoCamera.py | 74 | ||||
-rw-r--r-- | src/argaze.test/ArUcoMarkers/ArUcoScene.py | 92 | ||||
-rw-r--r-- | src/argaze.test/ArUcoMarkers/utils/aruco_camera.json (renamed from src/argaze.test/utils/environment.json) | 6 | ||||
-rw-r--r-- | src/argaze.test/ArUcoMarkers/utils/scene.obj | 2 |
5 files changed, 124 insertions, 125 deletions
diff --git a/src/argaze.test/ArFeatures.py b/src/argaze.test/ArFeatures.py deleted file mode 100644 index 765e9cf..0000000 --- a/src/argaze.test/ArFeatures.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python - -""" """ - -__author__ = "Théo de la Hogue" -__credits__ = [] -__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" -__license__ = "BSD" - -import unittest -import os - -from argaze import ArFeatures - -import numpy - -class TestArEnvironmentClass(unittest.TestCase): - """Test ArEnvironment class.""" - - def test_from_json(self): - """Test ArEnvironment creation from json file.""" - - # Edit test environment file path - current_directory = os.path.dirname(os.path.abspath(__file__)) - json_filepath = os.path.join(current_directory, 'utils/environment.json') - - # Load test environment - ar_environment = ArFeatures.ArEnvironment.from_json(json_filepath) - - # Check environment meta data - self.assertEqual(ar_environment.name, "TestEnvironment") - - # Check ArUco detector - self.assertEqual(ar_environment.aruco_detector.dictionary.name, "DICT_ARUCO_ORIGINAL") - self.assertEqual(ar_environment.aruco_detector.marker_size, 3.0) - self.assertEqual(ar_environment.aruco_detector.parameters.cornerRefinementMethod, 3) - self.assertEqual(ar_environment.aruco_detector.parameters.aprilTagQuadSigma, 2) - self.assertEqual(ar_environment.aruco_detector.parameters.aprilTagDeglitch, 1) - - # Check ArUco detector optic parameters - self.assertEqual(ar_environment.aruco_detector.optic_parameters.rms, 1.0) - self.assertIsNone(numpy.testing.assert_array_equal(ar_environment.aruco_detector.optic_parameters.dimensions, [1920, 1080])) - self.assertIsNone(numpy.testing.assert_array_equal(ar_environment.aruco_detector.optic_parameters.K, [[1.0, 0.0, 1.0], [0.0, 1.0, 1.0], [0.0, 0.0, 1.0]])) - self.assertIsNone(numpy.testing.assert_array_equal(ar_environment.aruco_detector.optic_parameters.D, [-1.0, -0.5, 0.0, 0.5, 1.0])) - - # Check environment scenes - self.assertEqual(len(ar_environment.scenes), 2) - self.assertIsNone(numpy.testing.assert_array_equal(list(ar_environment.scenes.keys()), ["TestSceneA", "TestSceneB"])) - - # Load test scene - ar_scene = ar_environment.scenes["TestSceneA"] - - # Check Aruco scene - self.assertEqual(len(ar_scene.aruco_scene.places), 2) - self.assertIsNone(numpy.testing.assert_array_equal(ar_scene.aruco_scene.places[0].translation, [1, 0, 0])) - self.assertIsNone(numpy.testing.assert_array_equal(ar_scene.aruco_scene.places[0].rotation, [[1.,0.,0.],[0.,1.,0.],[0.,0.,1.]])) - self.assertEqual(ar_scene.aruco_scene.places[0].marker.identifier, 0) - - self.assertIsNone(numpy.testing.assert_array_equal(ar_scene.aruco_scene.places[1].translation, [0, 1, 0])) - self.assertIsNone(numpy.testing.assert_array_almost_equal(ar_scene.aruco_scene.places[1].rotation, [[0.,0.,1.],[0., 1.,0.],[-1.,0.,0.]])) - self.assertEqual(ar_scene.aruco_scene.places[1].marker.identifier, 1) - - # Check AOI scene - self.assertEqual(len(ar_scene.aoi_scene.items()), 1) - self.assertEqual(ar_scene.aoi_scene['Test'].points_number, 4) - self.assertIsNone(numpy.testing.assert_array_equal(ar_scene.aoi_scene['Test'].size, [1., 1., 0.])) - - # Check ArScene - self.assertEqual(ar_scene.angle_tolerance, 1.0) - self.assertEqual(ar_scene.distance_tolerance, 2.0) - - -if __name__ == '__main__': - - unittest.main()
\ No newline at end of file diff --git a/src/argaze.test/ArUcoMarkers/ArUcoCamera.py b/src/argaze.test/ArUcoMarkers/ArUcoCamera.py new file mode 100644 index 0000000..6145f40 --- /dev/null +++ b/src/argaze.test/ArUcoMarkers/ArUcoCamera.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +""" """ + +__author__ = "Théo de la Hogue" +__credits__ = [] +__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" +__license__ = "BSD" + +import unittest +import os + +from argaze.ArUcoMarkers import ArUcoCamera + +import numpy + +class TestArUcoCameraClass(unittest.TestCase): + """Test ArUcoCamera class.""" + + def test_from_json(self): + """Test ArUcoCamera creation from json file.""" + + # Edit test aruco camera file path + current_directory = os.path.dirname(os.path.abspath(__file__)) + json_filepath = os.path.join(current_directory, 'utils/aruco_camera.json') + + # Load test aruco camera + aruco_camera = ArUcoCamera.ArUcoCamera.from_json(json_filepath) + + # Check aruco camera meta data + self.assertEqual(aruco_camera.name, "TestArUcoCamera") + + # Check ArUco detector + self.assertEqual(aruco_camera.aruco_detector.dictionary.name, "DICT_ARUCO_ORIGINAL") + self.assertEqual(aruco_camera.aruco_detector.marker_size, 3.0) + self.assertEqual(aruco_camera.aruco_detector.parameters.cornerRefinementMethod, 3) + self.assertEqual(aruco_camera.aruco_detector.parameters.aprilTagQuadSigma, 2) + self.assertEqual(aruco_camera.aruco_detector.parameters.aprilTagDeglitch, 1) + + # Check ArUco detector optic parameters + self.assertEqual(aruco_camera.aruco_detector.optic_parameters.rms, 1.0) + self.assertIsNone(numpy.testing.assert_array_equal(aruco_camera.aruco_detector.optic_parameters.dimensions, [1920, 1080])) + self.assertIsNone(numpy.testing.assert_array_equal(aruco_camera.aruco_detector.optic_parameters.K, [[1.0, 0.0, 1.0], [0.0, 1.0, 1.0], [0.0, 0.0, 1.0]])) + self.assertIsNone(numpy.testing.assert_array_equal(aruco_camera.aruco_detector.optic_parameters.D, [-1.0, -0.5, 0.0, 0.5, 1.0])) + + # Check camera scenes + self.assertEqual(len(aruco_camera.scenes), 2) + self.assertIsNone(numpy.testing.assert_array_equal(list(aruco_camera.scenes.keys()), ["TestSceneA", "TestSceneB"])) + + # Load test scene + ar_scene = aruco_camera.scenes["TestSceneA"] + + # Check Aruco scene + self.assertEqual(len(ar_scene.aruco_markers_group.places), 2) + self.assertIsNone(numpy.testing.assert_array_equal(ar_scene.aruco_markers_group.places[0].translation, [1, 0, 0])) + self.assertIsNone(numpy.testing.assert_array_equal(ar_scene.aruco_markers_group.places[0].rotation, [[1.,0.,0.],[0.,1.,0.],[0.,0.,1.]])) + self.assertEqual(ar_scene.aruco_markers_group.places[0].marker.identifier, 0) + + self.assertIsNone(numpy.testing.assert_array_equal(ar_scene.aruco_markers_group.places[1].translation, [0, 1, 0])) + self.assertIsNone(numpy.testing.assert_array_almost_equal(ar_scene.aruco_markers_group.places[1].rotation, [[0.,0.,1.],[0., 1.,0.],[-1.,0.,0.]])) + self.assertEqual(ar_scene.aruco_markers_group.places[1].marker.identifier, 1) + + # Check AOI scene + self.assertEqual(len(ar_scene.aoi_scene.items()), 1) + self.assertEqual(ar_scene.aoi_scene['Test'].points_number, 4) + self.assertIsNone(numpy.testing.assert_array_equal(ar_scene.aoi_scene['Test'].size, [1., 1., 0.])) + + # Check ArScene + self.assertEqual(ar_scene.angle_tolerance, 1.0) + self.assertEqual(ar_scene.distance_tolerance, 2.0) + +if __name__ == '__main__': + + unittest.main()
\ No newline at end of file diff --git a/src/argaze.test/ArUcoMarkers/ArUcoScene.py b/src/argaze.test/ArUcoMarkers/ArUcoScene.py index f334542..628eac5 100644 --- a/src/argaze.test/ArUcoMarkers/ArUcoScene.py +++ b/src/argaze.test/ArUcoMarkers/ArUcoScene.py @@ -11,12 +11,12 @@ import unittest import os import math -from argaze.ArUcoMarkers import ArUcoScene, ArUcoMarker +from argaze.ArUcoMarkers import ArUcoMarkersGroup, ArUcoMarker import cv2 as cv import numpy -class TestArUcoSceneClass(unittest.TestCase): +class TestArUcoMarkersGroupClass(unittest.TestCase): def new_from_obj(self): @@ -25,7 +25,7 @@ class TestArUcoSceneClass(unittest.TestCase): obj_filepath = os.path.join(current_directory, 'utils/scene.obj') # Load file - self.aruco_scene = ArUcoScene.ArUcoScene.from_obj(obj_filepath) + self.aruco_markers_group = ArUcoMarkersGroup.ArUcoMarkersGroup.from_obj(obj_filepath) def new_from_json(self): @@ -34,7 +34,7 @@ class TestArUcoSceneClass(unittest.TestCase): json_filepath = os.path.join(current_directory, 'utils/scene.json') # Load file - self.aruco_scene = ArUcoScene.ArUcoScene.from_json(json_filepath) + self.aruco_markers_group = ArUcoMarkersGroup.ArUcoMarkersGroup.from_json(json_filepath) def setup_markers(self): @@ -47,56 +47,56 @@ class TestArUcoSceneClass(unittest.TestCase): } # Prepare scene markers and remaining markers - self.scene_markers, self.remaining_markers = self.aruco_scene.filter_markers(self.detected_markers) + self.scene_markers, self.remaining_markers = self.aruco_markers_group.filter_markers(self.detected_markers) def test_new_from_obj(self): - """Test ArUcoScene creation.""" + """Test ArUcoMarkersGroup creation.""" self.new_from_obj() self.setup_markers() - # Check ArUcoScene creation - self.assertEqual(len(self.aruco_scene.places), 3) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.identifiers, [0, 1, 2])) - self.assertEqual(self.aruco_scene.marker_size, 1.) + # Check ArUcoMarkersGroup creation + self.assertEqual(len(self.aruco_markers_group.places), 3) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.identifiers, [0, 1, 2])) + self.assertEqual(self.aruco_markers_group.marker_size, 1.) - self.assertEqual(self.aruco_scene.places[0].marker.identifier, 0) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[0].translation, [0., 0., 0.])) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[0].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) + self.assertEqual(self.aruco_markers_group.places[0].marker.identifier, 0) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[0].translation, [0., 0., 0.])) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[0].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) - self.assertEqual(self.aruco_scene.places[1].marker.identifier, 1) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[1].translation, [10., 10., 0.])) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[1].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) + self.assertEqual(self.aruco_markers_group.places[1].marker.identifier, 1) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[1].translation, [10., 10., 0.])) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[1].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) - self.assertEqual(self.aruco_scene.places[2].marker.identifier, 2) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[2].translation, [0., 10., 0.])) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[2].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) + self.assertEqual(self.aruco_markers_group.places[2].marker.identifier, 2) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[2].translation, [0., 10., 0.])) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[2].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) def test_new_from_json(self): - """Test ArUcoScene creation.""" + """Test ArUcoMarkersGroup creation.""" self.new_from_json() self.setup_markers() - # Check ArUcoScene creation - self.assertEqual(len(self.aruco_scene.places), 3) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.identifiers, [0, 1, 2])) - self.assertEqual(self.aruco_scene.marker_size, 1.) + # Check ArUcoMarkersGroup creation + self.assertEqual(len(self.aruco_markers_group.places), 3) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.identifiers, [0, 1, 2])) + self.assertEqual(self.aruco_markers_group.marker_size, 1.) - self.assertEqual(self.aruco_scene.places[0].marker.identifier, 0) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[0].translation, [0., 0., 0.])) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[0].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) + self.assertEqual(self.aruco_markers_group.places[0].marker.identifier, 0) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[0].translation, [0., 0., 0.])) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[0].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) - self.assertEqual(self.aruco_scene.places[1].marker.identifier, 1) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[1].translation, [10., 10., 0.])) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[1].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) + self.assertEqual(self.aruco_markers_group.places[1].marker.identifier, 1) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[1].translation, [10., 10., 0.])) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[1].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) - self.assertEqual(self.aruco_scene.places[2].marker.identifier, 2) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[2].translation, [0., 10., 0.])) - self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_scene.places[2].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) + self.assertEqual(self.aruco_markers_group.places[2].marker.identifier, 2) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[2].translation, [0., 10., 0.])) + self.assertIsNone(numpy.testing.assert_array_equal(self.aruco_markers_group.places[2].rotation, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) def test_filter_markers(self): - """Test ArUcoScene markers filtering.""" + """Test ArUcoMarkersGroup markers filtering.""" self.new_from_obj() self.setup_markers() @@ -105,11 +105,11 @@ class TestArUcoSceneClass(unittest.TestCase): self.assertEqual(len(self.scene_markers), 3) self.assertEqual(len(self.remaining_markers), 1) - self.assertIsNone(numpy.testing.assert_array_equal(list(self.scene_markers.keys()), self.aruco_scene.identifiers)) + self.assertIsNone(numpy.testing.assert_array_equal(list(self.scene_markers.keys()), self.aruco_markers_group.identifiers)) self.assertIsNone(numpy.testing.assert_array_equal(list(self.remaining_markers.keys()), [3])) def test_check_markers_consistency(self): - """Test ArUcoScene markers consistency checking.""" + """Test ArUcoMarkersGroup markers consistency checking.""" self.new_from_obj() self.setup_markers() @@ -125,7 +125,7 @@ class TestArUcoSceneClass(unittest.TestCase): self.scene_markers[2].rotation = numpy.array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) # Check consistency - consistent_markers, unconsistent_markers, unconsistencies = self.aruco_scene.check_markers_consistency(self.scene_markers, 1, 1) + consistent_markers, unconsistent_markers, unconsistencies = self.aruco_markers_group.check_markers_consistency(self.scene_markers, 1, 1) # Check consistent markers, unconsistent markers and unconsistencies self.assertEqual(len(consistent_markers), 3) @@ -133,13 +133,13 @@ class TestArUcoSceneClass(unittest.TestCase): self.assertEqual(len(unconsistencies['rotation']), 0) self.assertEqual(len(unconsistencies['translation']), 0) - self.assertIsNone(numpy.testing.assert_array_equal(list(consistent_markers.keys()), self.aruco_scene.identifiers)) + self.assertIsNone(numpy.testing.assert_array_equal(list(consistent_markers.keys()), self.aruco_markers_group.identifiers)) # Edit unconsistent marker poses self.scene_markers[2].translation = numpy.array([5., 15., 5.]) # Check consistency - consistent_markers, unconsistent_markers, unconsistencies = self.aruco_scene.check_markers_consistency(self.scene_markers, 1, 1) + consistent_markers, unconsistent_markers, unconsistencies = self.aruco_markers_group.check_markers_consistency(self.scene_markers, 1, 1) # Check consistent markers, unconsistent markers and unconsistencies self.assertEqual(len(consistent_markers), 2) @@ -153,7 +153,7 @@ class TestArUcoSceneClass(unittest.TestCase): self.assertIsNone(numpy.testing.assert_array_equal(list(unconsistencies['translation']['1/2'].keys()), ['current', 'expected'])) def test_estimate_pose_from_single_marker(self): - """Test ArUcoScene pose estimation from single marker.""" + """Test ArUcoMarkersGroup pose estimation from single marker.""" self.new_from_obj() self.setup_markers() @@ -163,13 +163,13 @@ class TestArUcoSceneClass(unittest.TestCase): self.scene_markers[0].rotation = numpy.array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) # Estimate pose - tvec, rmat = self.aruco_scene.estimate_pose_from_single_marker(self.scene_markers[0]) + tvec, rmat = self.aruco_markers_group.estimate_pose_from_single_marker(self.scene_markers[0]) self.assertIsNone(numpy.testing.assert_array_equal(tvec, [1., 1., 5.])) self.assertIsNone(numpy.testing.assert_array_equal(rmat, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) def test_estimate_pose_from_markers(self): - """Test ArUcoScene pose estimation from markers.""" + """Test ArUcoMarkersGroup pose estimation from markers.""" self.new_from_obj() self.setup_markers() @@ -185,14 +185,14 @@ class TestArUcoSceneClass(unittest.TestCase): self.scene_markers[2].rotation = numpy.array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) # Estimate pose - tvec, rmat = self.aruco_scene.estimate_pose_from_markers(self.scene_markers) + tvec, rmat = self.aruco_markers_group.estimate_pose_from_markers(self.scene_markers) self.assertIsNone(numpy.testing.assert_array_equal(tvec, [1., 1., 5.])) self.assertIsNone(numpy.testing.assert_array_equal(rmat, [[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])) - @unittest.skip("ArUcoScene estimate_pose_from_axis_markers method is broken.") + @unittest.skip("ArUcoMarkersGroup estimate_pose_from_axis_markers method is broken.") def test_estimate_pose_from_axis_markers(self): - """Test ArUcoScene pose estimation from axis markers.""" + """Test ArUcoMarkersGroup pose estimation from axis markers.""" self.new_from_obj() self.setup_markers() @@ -208,7 +208,7 @@ class TestArUcoSceneClass(unittest.TestCase): self.scene_markers[2].rotation = numpy.array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) # Estimate pose - tvec, rmat = self.aruco_scene.estimate_pose_from_axis_markers(self.scene_markers[2], self.scene_markers[1], self.scene_markers[0]) + tvec, rmat = self.aruco_markers_group.estimate_pose_from_axis_markers(self.scene_markers[2], self.scene_markers[1], self.scene_markers[0]) self.assertIsNone(numpy.testing.assert_array_equal(tvec, [1., 1., 5.])) self.assertIsNone(numpy.testing.assert_array_equal(rmat, [[1., 0., 0.], [0., -1., 0.], [0., 0., -1.]])) diff --git a/src/argaze.test/utils/environment.json b/src/argaze.test/ArUcoMarkers/utils/aruco_camera.json index df1c771..7648916 100644 --- a/src/argaze.test/utils/environment.json +++ b/src/argaze.test/ArUcoMarkers/utils/aruco_camera.json @@ -1,5 +1,5 @@ { - "name": "TestEnvironment", + "name": "TestArUcoCamera", "aruco_detector": { "dictionary": { "name": "DICT_ARUCO_ORIGINAL" @@ -44,7 +44,7 @@ }, "scenes": { "TestSceneA" : { - "aruco_scene": { + "aruco_markers_group": { "marker_size": 3.0, "dictionary": { "name": "DICT_ARUCO_ORIGINAL" @@ -65,7 +65,7 @@ "distance_tolerance": 2.0 }, "TestSceneB" : { - "aruco_scene": { + "aruco_markers_group": { "marker_size": 3.0, "dictionary": { "name": "DICT_ARUCO_ORIGINAL" diff --git a/src/argaze.test/ArUcoMarkers/utils/scene.obj b/src/argaze.test/ArUcoMarkers/utils/scene.obj index 16c22a0..c233da2 100644 --- a/src/argaze.test/ArUcoMarkers/utils/scene.obj +++ b/src/argaze.test/ArUcoMarkers/utils/scene.obj @@ -1,4 +1,4 @@ -# .OBJ file for ArUcoScene unitary test +# .OBJ file for ArUcoMarkersGroup unitary test o DICT_ARUCO_ORIGINAL#0_Marker v -0.500000 -0.500000 0.000000 v 0.500000 -0.500000 0.000000 |