aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test
diff options
context:
space:
mode:
authorThéo de la Hogue2022-11-29 12:11:27 +0100
committerThéo de la Hogue2022-11-29 12:11:27 +0100
commitc48a37a3e0242b7effb028d074923e269b415d78 (patch)
treee6595aaa15e09da9160b81c021aeebcfe3dcad28 /src/argaze.test
parent0d58e3af1188a1e571c592f69c5289e5e477bb68 (diff)
downloadargaze-c48a37a3e0242b7effb028d074923e269b415d78.zip
argaze-c48a37a3e0242b7effb028d074923e269b415d78.tar.gz
argaze-c48a37a3e0242b7effb028d074923e269b415d78.tar.bz2
argaze-c48a37a3e0242b7effb028d074923e269b415d78.tar.xz
Adding new test for ArUcoCamera. Testing board tracking.
Diffstat (limited to 'src/argaze.test')
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoCamera.py42
-rw-r--r--src/argaze.test/ArUcoMarkers/ArUcoTracker.py23
-rw-r--r--src/argaze.test/ArUcoMarkers/utils/camera.json31
-rw-r--r--src/argaze.test/ArUcoMarkers/utils/full_hd_board.pngbin0 -> 18475 bytes
-rw-r--r--src/argaze.test/ArUcoMarkers/utils/full_hd_marker.png (renamed from src/argaze.test/ArUcoMarkers/utils/full_hd.png)bin116210 -> 116210 bytes
5 files changed, 94 insertions, 2 deletions
diff --git a/src/argaze.test/ArUcoMarkers/ArUcoCamera.py b/src/argaze.test/ArUcoMarkers/ArUcoCamera.py
new file mode 100644
index 0000000..7e50e8c
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/ArUcoCamera.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+import unittest
+import os
+
+from argaze.ArUcoMarkers import ArUcoCamera
+
+import numpy
+
+class TestArUcoCameraClass(unittest.TestCase):
+ """Test ArUcoCamera class."""
+
+ def test_new(self):
+ """Test ArUcoCamera creation."""
+
+ # Check defaut camera creation
+ aruco_camera = ArUcoCamera.ArUcoCamera()
+
+ # Check ArUco camera
+ self.assertEqual(aruco_camera.rms, 0.0)
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_camera.dimensions, numpy.array([0, 0])))
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_camera.K, ArUcoCamera.K0))
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_camera.D, ArUcoCamera.D0))
+
+ def test_from_json(self):
+
+ # Edit camera file path
+ current_directory = os.path.dirname(os.path.abspath(__file__))
+ json_filepath = os.path.join(current_directory, 'utils/camera.json')
+
+ # Load camera calibration
+ aruco_camera = ArUcoCamera.ArUcoCamera.from_json(json_filepath)
+
+ # Check ArUco camera
+ self.assertEqual(aruco_camera.rms, 1.0)
+ self.assertIsNone(numpy.testing.assert_array_equal(aruco_camera.dimensions, numpy.array([1920, 1080])))
+ self.assertIsNone(numpy.testing.assert_array_equal(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(aruco_camera.D, [-1.0, -0.5, 0.0, 0.5, 1.0]))
+
+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
index 67bbef9..acc0000 100644
--- a/src/argaze.test/ArUcoMarkers/ArUcoTracker.py
+++ b/src/argaze.test/ArUcoMarkers/ArUcoTracker.py
@@ -4,7 +4,7 @@ import unittest
import os
import math
-from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoCamera, ArUcoTracker
+from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoCamera, ArUcoTracker, ArUcoBoard
import cv2 as cv
import numpy
@@ -32,7 +32,7 @@ class TestArUcoTrackerClass(unittest.TestCase):
# 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'))
+ frame = cv.imread(os.path.join(current_directory, 'utils/full_hd_marker.png'))
# Check ArUcoMarker tracking
aruco_tracker.track(frame)
@@ -58,6 +58,25 @@ class TestArUcoTrackerClass(unittest.TestCase):
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/ArUcoMarkers/utils/camera.json b/src/argaze.test/ArUcoMarkers/utils/camera.json
new file mode 100644
index 0000000..988731c
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/utils/camera.json
@@ -0,0 +1,31 @@
+{
+ "rms": 1.0,
+ "dimensions": [
+ 1920,
+ 1080
+ ],
+ "K": [
+ [
+ 1.0,
+ 0.0,
+ 1.0
+ ],
+ [
+ 0.0,
+ 1.0,
+ 1.0
+ ],
+ [
+ 0.0,
+ 0.0,
+ 1.0
+ ]
+ ],
+ "D": [
+ -1.0,
+ -0.5,
+ 0.0,
+ 0.5,
+ 1.0
+ ]
+} \ No newline at end of file
diff --git a/src/argaze.test/ArUcoMarkers/utils/full_hd_board.png b/src/argaze.test/ArUcoMarkers/utils/full_hd_board.png
new file mode 100644
index 0000000..d30b300
--- /dev/null
+++ b/src/argaze.test/ArUcoMarkers/utils/full_hd_board.png
Binary files differ
diff --git a/src/argaze.test/ArUcoMarkers/utils/full_hd.png b/src/argaze.test/ArUcoMarkers/utils/full_hd_marker.png
index 42146fe..42146fe 100644
--- a/src/argaze.test/ArUcoMarkers/utils/full_hd.png
+++ b/src/argaze.test/ArUcoMarkers/utils/full_hd_marker.png
Binary files differ