Esempio n. 1
0
    def test_translation_4x4(self):
        offset = 10.
        trans_01 = identity_matrix(batch_size=1)[0]
        trans_02 = identity_matrix(batch_size=1)[0]
        trans_02[..., :3, -1] += offset  # add offset to translation vector

        trans_12 = kornia.relative_transformation(trans_01, trans_02)
        trans_02_hat = kornia.compose_transformations(trans_01, trans_12)
        assert_allclose(trans_02_hat, trans_02)
Esempio n. 2
0
    def test_translation_4x4(self, device, dtype):
        offset = 10.0
        trans_01 = identity_matrix(batch_size=1, device=device, dtype=dtype)[0]
        trans_02 = identity_matrix(batch_size=1, device=device, dtype=dtype)[0]
        trans_02[..., :3, -1] += offset  # add offset to translation vector

        trans_12 = kornia.relative_transformation(trans_01, trans_02)
        trans_02_hat = kornia.compose_transformations(trans_01, trans_12)
        assert_close(trans_02_hat, trans_02, atol=1e-4, rtol=1e-4)
Esempio n. 3
0
    def test_rotation_translation_Bx4x4(self, batch_size):
        offset = 10.
        x, y, z = 0., 0., kornia.pi
        ones = torch.ones(batch_size)
        rmat_02 = euler_angles_to_rotation_matrix(x * ones, y * ones, z * ones)

        trans_01 = identity_matrix(batch_size)
        trans_02 = identity_matrix(batch_size)
        trans_02[..., :3, -1] += offset  # add offset to translation vector
        trans_02[..., :3, :3] = rmat_02[..., :3, :3]

        trans_12 = kornia.relative_transformation(trans_01, trans_02)
        trans_02_hat = kornia.compose_transformations(trans_01, trans_12)
        assert_allclose(trans_02_hat, trans_02)
Esempio n. 4
0
    def __init__(self, current_matrix: np.ndarray, next_matrix: np.ndarray):
        self._current_position_name = "current_position"
        self._current_angle_name = "current_angle"
        self._next_position_name = "next_position"
        self._next_angle_name = "next_angle"
        self._delta_position_name = "delta_position"
        self._delta_angle_name = "delta_angle"

        self._current_angle = kornia.rotation_matrix_to_angle_axis(
            torch.from_numpy(current_matrix[:3, :3].astype('float32')).reshape(
                1, 3, 3)).permute(1, 0).squeeze()
        self._next_angle = kornia.rotation_matrix_to_angle_axis(
            torch.from_numpy(next_matrix[:3, :3].astype('float32')).reshape(
                1, 3, 3)).permute(1, 0).squeeze()
        self._current_position = torch.from_numpy(current_matrix[:3, 3])
        self._next_position = torch.from_numpy(next_matrix[:3, 3])

        delta_matrix = kornia.relative_transformation(
            torch.from_numpy(current_matrix.astype('float32')),
            torch.from_numpy(next_matrix.astype('float32')))
        rotation_matrix = delta_matrix[:3, :3].reshape(1, 3, 3).clone()
        self._delta_angle = kornia.rotation_matrix_to_angle_axis(
            rotation_matrix).permute(1, 0).squeeze()
        self._delta_position = delta_matrix[:3, 3]