aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test/ArUcoMarkers/ArUcoCamera.py
blob: 7a5307044b1ebb4e51407805416612852632679a (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
#!/usr/bin/env python

""" """

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

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.assertEqual(type(aruco_camera.K), numpy.array)

        self.assertIsNone(numpy.testing.assert_array_equal(aruco_camera.dimensions, [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, [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()