def test_rotate_z(self, device, dtype): R1 = torch.tensor([[ [1., 0., 0.], [0., 1., 0.], [0., 0., 1.], ]], device=device, dtype=dtype) R2 = torch.tensor([[ [0., 0., 0.], [0., 0., 0.], [0., 0., 1.], ]], device=device, dtype=dtype) t1 = epi.vec_like(3, R1) t2 = epi.vec_like(3, R2) R_expected = R2.clone() t_expected = t1 R, t = epi.relative_camera_motion(R1, t1, R2, t2) assert_allclose(R_expected, R) assert_allclose(t_expected, t)
def test_smoke(self, device, dtype): R1 = torch.rand(1, 3, 3, device=device, dtype=dtype) t1 = torch.rand(1, 3, 1, device=device, dtype=dtype) R2 = torch.rand(1, 3, 3, device=device, dtype=dtype) t2 = torch.rand(1, 3, 1, device=device, dtype=dtype) R, t = epi.relative_camera_motion(R1, t1, R2, t2) assert R.shape == (1, 3, 3) assert t.shape == (1, 3, 1)
def test_shape(self, batch_size, device, dtype): B: int = batch_size R1 = torch.rand(B, 3, 3, device=device, dtype=dtype) t1 = torch.rand(B, 3, 1, device=device, dtype=dtype) R2 = torch.rand(1, 3, 3, device=device, dtype=dtype) # check broadcasting t2 = torch.rand(B, 3, 1, device=device, dtype=dtype) R, t = epi.relative_camera_motion(R1, t1, R2, t2) assert R.shape == (B, 3, 3) assert t.shape == (B, 3, 1)
def test_translation(self, device, dtype): R1 = torch.tensor([[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]], device=device, dtype=dtype) t1 = torch.tensor([[[10.0], [0.0], [0.0]]]).type_as(R1) R2 = kornia.eye_like(3, R1) t2 = kornia.vec_like(3, t1) R_expected = R1.clone() t_expected = -t1 R, t = epi.relative_camera_motion(R1, t1, R2, t2) assert_close(R_expected, R) assert_close(t_expected, t)
def test_two_view(self, device, dtype): scene = utils.generate_two_view_random_scene(device, dtype) E_mat = epi.essential_from_Rt(scene['R1'], scene['t1'], scene['R2'], scene['t2']) R, t = epi.relative_camera_motion(scene['R1'], scene['t1'], scene['R2'], scene['t2']) t = torch.nn.functional.normalize(t, dim=1) R_hat, t_hat, _ = epi.motion_from_essential_choose_solution( E_mat, scene['K1'], scene['K2'], scene['x1'], scene['x2'] ) assert_close(t, t_hat) assert_close(R, R_hat, rtol=1e-4, atol=1e-4)
def test_two_view(self, device, dtype): scene = utils.generate_two_view_random_scene(device, dtype) R1, t1 = scene['R1'], scene['t1'] R2, t2 = scene['R2'], scene['t2'] E_mat = epi.essential_from_Rt(R1, t1, R2, t2) R, t = epi.relative_camera_motion(R1, t1, R2, t2) t = torch.nn.functional.normalize(t, dim=1) Rs, ts = epi.motion_from_essential(E_mat) rot_error = (Rs - R).abs().sum((-2, -1)) vec_error = (ts - t).abs().sum((-1)) rtol: float = 1e-4 assert (rot_error < rtol).any() & (vec_error < rtol).any()