aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test
diff options
context:
space:
mode:
Diffstat (limited to 'src/argaze.test')
-rw-r--r--src/argaze.test/ArScene.py8
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoDetector.py105
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoTracker.py105
-rw-r--r--src/argaze.test/utils/scene.json2
4 files changed, 110 insertions, 110 deletions
diff --git a/src/argaze.test/ArScene.py b/src/argaze.test/ArScene.py
index 449530b..5180c12 100644
--- a/src/argaze.test/ArScene.py
+++ b/src/argaze.test/ArScene.py
@@ -31,10 +31,10 @@ class TestArSceneClass(unittest.TestCase):
self.assertIsNone(numpy.testing.assert_array_equal(ar_scene.aruco_camera.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_scene.aruco_camera.D, [-1.0, -0.5, 0.0, 0.5, 1.0]))
- # Check ArUco tracker
- self.assertEqual(ar_scene.aruco_tracker.tracking_data.cornerRefinementMethod, 3)
- self.assertEqual(ar_scene.aruco_tracker.tracking_data.aprilTagQuadSigma, 2)
- self.assertEqual(ar_scene.aruco_tracker.tracking_data.aprilTagDeglitch, 1)
+ # Check ArUco detecter
+ self.assertEqual(ar_scene.aruco_detector.detection_parameters.cornerRefinementMethod, 3)
+ self.assertEqual(ar_scene.aruco_detector.detection_parameters.aprilTagQuadSigma, 2)
+ self.assertEqual(ar_scene.aruco_detector.detection_parameters.aprilTagDeglitch, 1)
# Check ArUco scene
self.assertEqual(ar_scene.angle_tolerance, 1.0)
diff --git a/src/argaze.test/ArUcoMarkers/ArUcoDetector.py b/src/argaze.test/ArUcoMarkers/ArUcoDetector.py
new file mode 100644
index 0000000..ab29024
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/ArUcoDetector.py
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+
+import unittest
+import os
+import math
+
+from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoCamera, ArUcoDetector, ArUcoBoard
+
+import cv2 as cv
+import numpy
+
+class TestDetectionParametersClass(unittest.TestCase):
+ """Test DetectionParameters class."""
+
+ def test_from_json(self):
+ """Test DetectionParameters creation from json file."""
+
+ # Edit traking data file path
+ current_directory = os.path.dirname(os.path.abspath(__file__))
+ json_filepath = os.path.join(current_directory, 'utils/detecter.json')
+
+ # Load project
+ detection_parameters = ArUcoDetector.DetectionParameters.from_json(json_filepath)
+
+ # Check data
+ self.assertEqual(detection_parameters.cornerRefinementMethod, 3)
+ self.assertEqual(detection_parameters.aprilTagQuadSigma, 2)
+ self.assertEqual(detection_parameters.aprilTagDeglitch, 1)
+
+ # Check bad data access fails
+ with self.assertRaises(AttributeError):
+
+ detection_parameters.unknown_data = 1
+
+class TestArUcoDetectorClass(unittest.TestCase):
+ """Test ArUcoDetector class."""
+
+ def test_new(self):
+ """Test ArUcoDetector creation."""
+
+ aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
+ aruco_camera = ArUcoCamera.ArUcoCamera()
+ aruco_detector = ArUcoDetector.ArUcoDetector(aruco_dictionary, 3, aruco_camera)
+
+ # Check ArUcoDetector creation
+ self.assertEqual(aruco_detector.detected_markers_number, 0)
+ self.assertEqual(aruco_detector.detected_markers, {})
+
+ def test_detect(self):
+ """Test detect method."""
+
+ aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
+ aruco_camera = ArUcoCamera.ArUcoCamera()
+ aruco_detector = ArUcoDetector.ArUcoDetector(aruco_dictionary, 3, aruco_camera)
+
+ # Load picture Full HD to test ArUcoMarker detection
+ current_directory = os.path.dirname(os.path.abspath(__file__))
+ frame = cv.imread(os.path.join(current_directory, 'utils/full_hd_marker.png'))
+
+ # Check ArUcoMarker detection
+ aruco_detector.detect(frame)
+
+ self.assertEqual(aruco_detector.detected_markers_number, 1)
+
+ self.assertEqual(aruco_detector.detected_markers[0].dictionary, aruco_dictionary)
+ self.assertEqual(aruco_detector.detected_markers[0].identifier, 0)
+ self.assertEqual(aruco_detector.detected_markers[0].size, 3)
+
+ # Check corner positions with -/+ 10 pixels precision
+ self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].corners[0][0].astype(int), numpy.array([3823, 2073]), decimal=-1))
+ self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].corners[0][1].astype(int), numpy.array([4177, 2073]), decimal=-1))
+ self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].corners[0][2].astype(int), numpy.array([4177, 2427]), decimal=-1))
+ self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].corners[0][3].astype(int), numpy.array([3823, 2427]), decimal=-1))
+
+ # Check marker translation with -/+ 0.1 cm precision and rotation with -/+ 0.001 radian precision
+ self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].translation, numpy.array([33.87, 19.05, 0.]), decimal=1))
+ self.assertIsNone(numpy.testing.assert_almost_equal(aruco_detector.detected_markers[0].rotation, numpy.array([math.pi, 0., 0.]), decimal=3))
+
+ # Check detect metrics
+ detect_count, markers_count = aruco_detector.detection_metrics
+ self.assertEqual(detect_count, 1)
+ self.assertEqual(markers_count[0], 1)
+
+ def test_detect_board(self):
+ """Test detect board method."""
+
+ aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
+ aruco_board = ArUcoBoard.ArUcoBoard(aruco_dictionary, 7, 5, 5, 3)
+ aruco_camera = ArUcoCamera.ArUcoCamera()
+ aruco_detector = ArUcoDetector.ArUcoDetector(aruco_dictionary, 3, aruco_camera)
+
+ # Load picture Full HD to test ArUcoMarker board detection
+ current_directory = os.path.dirname(os.path.abspath(__file__))
+ frame = cv.imread(os.path.join(current_directory, 'utils/full_hd_board.png'))
+
+ # Check ArUcoMarker board detection
+ aruco_detector.detect_board(frame, aruco_board, aruco_board.markers_number)
+
+ self.assertEqual(aruco_detector.board_corners_number, aruco_board.corners_number)
+ self.assertEqual(len(aruco_detector.board_corners), 24)
+ self.assertEqual(len(aruco_detector.board_corners_identifier), 24)
+
+if __name__ == '__main__':
+
+ unittest.main() \ No newline at end of file
diff --git a/src/argaze.test/ArUcoMarkers/ArUcoTracker.py b/src/argaze.test/ArUcoMarkers/ArUcoTracker.py
deleted file mode 100644
index 87373ea..0000000
--- a/src/argaze.test/ArUcoMarkers/ArUcoTracker.py
+++ /dev/null
@@ -1,105 +0,0 @@
-#!/usr/bin/env python
-
-import unittest
-import os
-import math
-
-from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoCamera, ArUcoTracker, ArUcoBoard
-
-import cv2 as cv
-import numpy
-
-class TestTrackingDataClass(unittest.TestCase):
- """Test TrackingData class."""
-
- def test_from_json(self):
- """Test TrackingData creation from json file."""
-
- # Edit traking data file path
- current_directory = os.path.dirname(os.path.abspath(__file__))
- json_filepath = os.path.join(current_directory, 'utils/tracker.json')
-
- # Load project
- tracking_data = ArUcoTracker.TrackingData.from_json(json_filepath)
-
- # Check data
- self.assertEqual(tracking_data.cornerRefinementMethod, 3)
- self.assertEqual(tracking_data.aprilTagQuadSigma, 2)
- self.assertEqual(tracking_data.aprilTagDeglitch, 1)
-
- # Check bad data access fails
- with self.assertRaises(AttributeError):
-
- tracking_data.unknown_data = 1
-
-class TestArUcoTrackerClass(unittest.TestCase):
- """Test ArUcoTracker class."""
-
- def test_new(self):
- """Test ArUcoTracker creation."""
-
- aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
- aruco_camera = ArUcoCamera.ArUcoCamera()
- aruco_tracker = ArUcoTracker.ArUcoTracker(aruco_dictionary, 3, aruco_camera)
-
- # Check ArUcoTracker creation
- self.assertEqual(aruco_tracker.tracked_markers_number, 0)
- self.assertEqual(aruco_tracker.tracked_markers, {})
-
- def test_track(self):
- """Test track method."""
-
- aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
- aruco_camera = ArUcoCamera.ArUcoCamera()
- aruco_tracker = ArUcoTracker.ArUcoTracker(aruco_dictionary, 3, aruco_camera)
-
- # Load picture Full HD to test ArUcoMarker tracking
- current_directory = os.path.dirname(os.path.abspath(__file__))
- frame = cv.imread(os.path.join(current_directory, 'utils/full_hd_marker.png'))
-
- # Check ArUcoMarker tracking
- aruco_tracker.track(frame)
-
- self.assertEqual(aruco_tracker.tracked_markers_number, 1)
-
- self.assertEqual(aruco_tracker.tracked_markers[0].dictionary, aruco_dictionary)
- self.assertEqual(aruco_tracker.tracked_markers[0].identifier, 0)
- self.assertEqual(aruco_tracker.tracked_markers[0].size, 3)
-
- # Check corner positions with -/+ 10 pixels precision
- self.assertIsNone(numpy.testing.assert_almost_equal(aruco_tracker.tracked_markers[0].corners[0][0].astype(int), numpy.array([3823, 2073]), decimal=-1))
- self.assertIsNone(numpy.testing.assert_almost_equal(aruco_tracker.tracked_markers[0].corners[0][1].astype(int), numpy.array([4177, 2073]), decimal=-1))
- self.assertIsNone(numpy.testing.assert_almost_equal(aruco_tracker.tracked_markers[0].corners[0][2].astype(int), numpy.array([4177, 2427]), decimal=-1))
- self.assertIsNone(numpy.testing.assert_almost_equal(aruco_tracker.tracked_markers[0].corners[0][3].astype(int), numpy.array([3823, 2427]), decimal=-1))
-
- # Check marker translation with -/+ 0.1 cm precision and rotation with -/+ 0.001 radian precision
- self.assertIsNone(numpy.testing.assert_almost_equal(aruco_tracker.tracked_markers[0].translation, numpy.array([33.87, 19.05, 0.]), decimal=1))
- self.assertIsNone(numpy.testing.assert_almost_equal(aruco_tracker.tracked_markers[0].rotation, numpy.array([math.pi, 0., 0.]), decimal=3))
-
- # Check track metrics
- track_count, markers_count = aruco_tracker.track_metrics
- self.assertEqual(track_count, 1)
- self.assertEqual(markers_count[0], 1)
-
- def test_track_board(self):
- """Test track board method."""
-
- aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
- aruco_board = ArUcoBoard.ArUcoBoard(aruco_dictionary, 7, 5, 5, 3)
- aruco_camera = ArUcoCamera.ArUcoCamera()
- aruco_tracker = ArUcoTracker.ArUcoTracker(aruco_dictionary, 3, aruco_camera)
-
- # Load picture Full HD to test ArUcoMarker board tracking
- current_directory = os.path.dirname(os.path.abspath(__file__))
- frame = cv.imread(os.path.join(current_directory, 'utils/full_hd_board.png'))
-
- # Check ArUcoMarker board tracking
- aruco_tracker.track_board(frame, aruco_board, aruco_board.markers_number)
-
- self.assertEqual(aruco_tracker.board_corners_number, aruco_board.corners_number)
- self.assertEqual(len(aruco_tracker.board_corners), 24)
- self.assertEqual(len(aruco_tracker.board_corners_identifier), 24)
-
-if __name__ == '__main__':
-
- unittest.main() \ No newline at end of file
diff --git a/src/argaze.test/utils/scene.json b/src/argaze.test/utils/scene.json
index 4e1cc20..25aacc8 100644
--- a/src/argaze.test/utils/scene.json
+++ b/src/argaze.test/utils/scene.json
@@ -33,7 +33,7 @@
1.0
]
},
- "aruco_tracker": {
+ "aruco_detector": {
"cornerRefinementMethod": 3,
"aprilTagQuadSigma": 2,
"aprilTagDeglitch": 1