aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test/ArUcoMarkers/ArUcoTracker.py
diff options
context:
space:
mode:
authorThéo de la Hogue2022-11-21 19:29:57 +0100
committerThéo de la Hogue2022-11-21 19:29:57 +0100
commitd36362bbb9d168cc612bfd163fa04d151ad362aa (patch)
treea078d3368c1cd2984f2c447952defe42ce06fc22 /src/argaze.test/ArUcoMarkers/ArUcoTracker.py
parent703e8ca71f4675fc9c536edf7d2124eb29e39873 (diff)
downloadargaze-d36362bbb9d168cc612bfd163fa04d151ad362aa.zip
argaze-d36362bbb9d168cc612bfd163fa04d151ad362aa.tar.gz
argaze-d36362bbb9d168cc612bfd163fa04d151ad362aa.tar.bz2
argaze-d36362bbb9d168cc612bfd163fa04d151ad362aa.tar.xz
Testing ArUcoMarkers submodule.
Diffstat (limited to 'src/argaze.test/ArUcoMarkers/ArUcoTracker.py')
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoTracker.py63
1 files changed, 63 insertions, 0 deletions
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