-
Notifications
You must be signed in to change notification settings - Fork 79
/
test_rigid_transform_3D.py
executable file
·66 lines (48 loc) · 1.04 KB
/
test_rigid_transform_3D.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
import numpy as np
from rigid_transform_3D import rigid_transform_3D
# Test with random data
# Random rotation and translation
R = np.random.rand(3,3)
t = np.random.rand(3,1)
# make R a proper rotation matrix, force orthonormal
U, S, Vt = np.linalg.svd(R)
R = U@Vt
# remove reflection
if np.linalg.det(R) < 0:
Vt[2,:] *= -1
R = U@Vt
# number of points
n = 10
A = np.random.rand(3, n)
B = R@A + t
# Recover R and t
ret_R, ret_t = rigid_transform_3D(A, B)
# Compare the recovered R and t with the original
B2 = (ret_R@A) + ret_t
# Find the root mean squared error
err = B2 - B
err = err * err
err = np.sum(err)
rmse = np.sqrt(err/n)
print("Points A")
print(A)
print("")
print("Points B")
print(B)
print("")
print("Ground truth rotation")
print(R)
print("Recovered rotation")
print(ret_R)
print("")
print("Ground truth translation")
print(t)
print("Recovered translation")
print(ret_t)
print("")
print("RMSE:", rmse)
if rmse < 1e-5:
print("Everything looks good!")
else:
print("Hmm something doesn't look right ...")