VictorYuki commited on
Commit
ef5e4fa
·
verified ·
1 Parent(s): 59e5a6d

Upload tools.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. tools.py +48 -0
tools.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+
4
+ def degrees_to_radians(degrees):
5
+ return degrees * np.pi / 180
6
+
7
+ def compute_rotation_list(params):
8
+ x, y, z, yaw, pitch = params
9
+
10
+ yaw_rad = degrees_to_radians(yaw)
11
+ pitch_rad = degrees_to_radians(pitch)
12
+
13
+ R_y = np.array([[np.cos(yaw_rad), 0, np.sin(yaw_rad)],
14
+ [0, 1, 0],
15
+ [-np.sin(yaw_rad), 0, np.cos(yaw_rad)]])
16
+
17
+ R_z = np.array([[np.cos(pitch_rad), -np.sin(pitch_rad), 0],
18
+ [np.sin(pitch_rad), np.cos(pitch_rad), 0],
19
+ [0, 0, 1]])
20
+
21
+ R = np.dot(R_z, R_y)
22
+
23
+ rotation_list = [x, y, z] + R.flatten().tolist()
24
+
25
+ return rotation_list
26
+
27
+ def convert_rt_to_relative(rt_list_all, ref_rt):
28
+ def parse_rt(rt):
29
+ t = np.array(rt[:3]).reshape((3, 1))
30
+ R = np.array(rt[3:]).reshape((3, 3))
31
+ return R, t
32
+
33
+ R_ref, T_ref = parse_rt(ref_rt)
34
+ R_ref_inv = R_ref.T
35
+ T_ref_inv = -R_ref_inv @ T_ref
36
+
37
+ new_rt_list = []
38
+
39
+ for rt in rt_list_all:
40
+ R_i, T_i = parse_rt(rt)
41
+
42
+ R_new = R_ref_inv @ R_i
43
+ T_new = R_ref_inv @ T_i + T_ref_inv
44
+
45
+ rt_new = T_new.flatten().tolist() + R_new.flatten().tolist()
46
+ new_rt_list.append(rt_new)
47
+
48
+ return new_rt_list