aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoMarker.py24
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoMarkersDictionary.py27
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoTracker.py63
-rw-r--r--src/argaze.test/ArUcoMarkers/utils/full_hd.pngbin0 -> 116210 bytes
4 files changed, 114 insertions, 0 deletions
diff --git a/src/argaze.test/ArUcoMarkers/ArUcoMarker.py b/src/argaze.test/ArUcoMarkers/ArUcoMarker.py
new file mode 100644
index 0000000..0b86d7e
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/ArUcoMarker.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+import unittest
+
+from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoMarker
+
+class TestArUcoMarkerClass(unittest.TestCase):
+ """Test ArUcoMarker class."""
+
+ def test_new(self):
+ """Test ArUcoMarker creation."""
+
+ # Check DICT_ARUCO_ORIGINAL ArUcoMarker creation
+ aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
+
+ aruco_marker = aruco_dictionary.create_marker(0, 3)
+
+ self.assertEqual(aruco_marker.dictionary, aruco_dictionary)
+ self.assertEqual(aruco_marker.identifier, 0)
+ self.assertEqual(aruco_marker.size, 3)
+
+if __name__ == '__main__':
+
+ unittest.main() \ No newline at end of file
diff --git a/src/argaze.test/ArUcoMarkers/ArUcoMarkersDictionary.py b/src/argaze.test/ArUcoMarkers/ArUcoMarkersDictionary.py
new file mode 100644
index 0000000..58849a6
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/ArUcoMarkersDictionary.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+import unittest
+
+from argaze.ArUcoMarkers import ArUcoMarkersDictionary
+
+class TestArUcoMarkersDictionaryClass(unittest.TestCase):
+ """Test ArUcoMarkersDictionary class."""
+
+ def test_new(self):
+ """Test ArUcoMarkersDictionary creation."""
+
+ # Check that ArUcoMarkersDictionary creation fails with bad name
+ with self.assertRaises(NameError):
+
+ aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('BAD_DICT_NAME')
+
+ # Check DICT_ARUCO_ORIGINAL ArUcoMarkersDictionary creation
+ aruco_dictionary = ArUcoMarkersDictionary.ArUcoMarkersDictionary('DICT_ARUCO_ORIGINAL')
+
+ self.assertEqual(aruco_dictionary.name, 'DICT_ARUCO_ORIGINAL')
+ self.assertEqual(aruco_dictionary.format, '5X5')
+ self.assertEqual(aruco_dictionary.number, 1024)
+
+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
new file mode 100644
index 0000000..67bbef9
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/ArUcoTracker.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+import unittest
+import os
+import math
+
+from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoCamera, ArUcoTracker
+
+import cv2 as cv
+import numpy
+
+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.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)
+
+if __name__ == '__main__':
+
+ unittest.main() \ No newline at end of file
diff --git a/src/argaze.test/ArUcoMarkers/utils/full_hd.png b/src/argaze.test/ArUcoMarkers/utils/full_hd.png
new file mode 100644
index 0000000..42146fe
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/utils/full_hd.png
Binary files differ