def test_eq(self):
        fx, fy, cx, cy, skew = 2, 6, 4, 7, 3

        camera_matrix_1 = CameraMatrix(fx=fx, fy=fy, cx=cx, cy=cy, skew=skew)
        camera_matrix_2 = CameraMatrix(fx=fx, fy=fy, cx=cx, cy=cy, skew=skew)
        camera_matrix_3 = CameraMatrix(matrix=[[0, 0, 0], [0, 0, 0], [0, 0, 0]])

        assert (camera_matrix_1 == camera_matrix_2) == True
        assert (camera_matrix_1 == camera_matrix_3) == False
    def test_loads(self):
        cameramatrix = CameraMatrix.loads(_CAMERA_MATRIX_DATA)

        assert cameramatrix.fx == 2
        assert cameramatrix.fy == 6
        assert cameramatrix.cx == 4
        assert cameramatrix.cy == 7
        assert cameramatrix.skew == 3
Beispiel #3
0
 def test_set_camera_matrix(self):
     camera = Camera("test")
     camera.set_camera_matrix(fx=1, fy=2, cx=3, cy=4)
     assert camera.intrinsics.camera_matrix == CameraMatrix(fx=1,
                                                            fy=2,
                                                            cx=3,
                                                            cy=4,
                                                            skew=0)
    def test_init(self):
        with pytest.raises(TypeError):
            CameraMatrix()
        with pytest.raises(TypeError):
            CameraMatrix(fx=1, fy=2)

        camera_matrix_1 = CameraMatrix(matrix=_3x3_MATRIX)

        assert camera_matrix_1.fx == 1
        assert camera_matrix_1.fy == 4
        assert camera_matrix_1.cx == 3
        assert camera_matrix_1.cy == 5
        assert camera_matrix_1.skew == 2

        camera_matrix_1 = CameraMatrix(1, 2, 3, 4)
        assert camera_matrix_1.fx == 1
        assert camera_matrix_1.fy == 2
        assert camera_matrix_1.cx == 3
        assert camera_matrix_1.cy == 4
        assert camera_matrix_1.skew == 0
    def test_dumps(self):
        fx, fy, cx, cy, skew = 2, 6, 4, 7, 3
        camera_matrix_1 = CameraMatrix(fx=fx, fy=fy, cx=cx, cy=cy, skew=skew)
        assert camera_matrix_1.dumps() == _CAMERA_MATRIX_DATA

        camera_matrix_2 = CameraMatrix(fx=fx, fy=fy, cx=cx, cy=cy)
        assert camera_matrix_2.dumps() == _CAMERA_MATRIX_NO_SKEW_DATA
    def test_project(self):
        camera_matrix = CameraMatrix(matrix=_3x3_MATRIX)

        with pytest.raises(TypeError):
            camera_matrix.project([])
        with pytest.raises(TypeError):
            camera_matrix.project([1])
        with pytest.raises(TypeError):
            camera_matrix.project([1, 1, 1, 1])
        with pytest.raises(ZeroDivisionError):
            camera_matrix.project([0, 0, 0])

        assert camera_matrix.project([0, 0]) == Vector2D(3, 5)
        assert camera_matrix.project([1, 2]) == Vector2D(8, 13)
        assert camera_matrix.project([1, 2, 4]) == Vector2D(4.25, 7.0)
 def test_as_matrix(self):
     camera_matrix = CameraMatrix(matrix=_3x3_MATRIX).as_matrix()
     assert np.all(np.array(camera_matrix) == _3x3_NUMPY)
    def test_set_camera_matrix(self):
        camera_intrinsics = CameraIntrinsics(fx=0, fy=0, cx=0, cy=0, p1=0, p2=0, k1=0, k2=0)
        camera_intrinsics.set_camera_matrix(fx=2, fy=6, cx=4, cy=7, skew=3)

        assert camera_intrinsics.camera_matrix == CameraMatrix(fx=2, fy=6, cx=4, cy=7, skew=3)