aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test/ArUcoMarkers/ArUcoCamera.py
blob: ef78b04d61c856cfefa5a332b3321d0fb5b0f0e6 (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
#!/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.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()