aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test/ArUcoMarker/ArUcoCamera.py
blob: 0777beb2181dbc25e5e182e304ef211c4a9d2a72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
""" """

"""
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
"""

__author__ = "Théo de la Hogue"
__credits__ = []
__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "GPLv3"

import unittest
import os

import argaze

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
        with argaze.load(json_filepath) as aruco_camera:

            # 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.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_allclose(ar_scene.aruco_markers_group.places[0].corners[0], [-0.5, 1.5, 0.], rtol=0, atol=1e-3))
            self.assertEqual(ar_scene.aruco_markers_group.places[0].marker.identifier, 0)

            self.assertIsNone(numpy.testing.assert_allclose(ar_scene.aruco_markers_group.places[1].corners[0], [0., 2.5, -1.5], rtol=0, atol=1e-3))
            self.assertEqual(ar_scene.aruco_markers_group.places[1].marker.identifier, 1)

             # Check layers and AOI scene 
            self.assertEqual(len(ar_scene.layers.items()), 1)
            self.assertEqual(len(ar_scene.layers["Main"].aoi_scene), 1)
            self.assertEqual(ar_scene.layers["Main"].aoi_scene['Test'].points_number, 4)
        
if __name__ == '__main__':

    unittest.main()