MCPcopy Create free account
hub / github.com/ComputationalRobotics/XM-code / load_tum_gt

Function load_tum_gt

utils/readgt_TUM.py:16–59  ·  view source on GitHub ↗
(dataset_path)

Source from the content-addressed store, hash-verified

14 return R
15
16def load_tum_gt(dataset_path):
17
18 results = {}
19 image_dir = dataset_path + "/images/"
20 # get all filename
21 all_files = sorted([f for f in os.listdir(image_dir) if os.path.isfile(os.path.join(image_dir, f))])
22 fx = 517.3 # focal length x
23 fy = 516.5 # focal length y
24 cx = 318.6 # optical center x
25 cy = 255.3 # optical center y
26 K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]])
27 # Read ground truth poses and timestamps
28 gtname = dataset_path + "/groundtruth.txt"
29 data = pd.read_csv(gtname, sep=' ', header=None, names=['t', 'tx', 'ty', 'tz', 'qx', 'qy', 'qz', 'qw'])
30
31 timestamps = data['t'].values
32 txyz = data[['tx', 'ty', 'tz']].values
33 q = data[['qw', 'qx', 'qy', 'qz']].values
34
35 # load all image in 'image' folder
36 for i in range(len(all_files)):
37 timestamp = float(all_files[i].replace('.png', ''))
38 insert_position = np.searchsorted(timestamps, timestamp)
39 if insert_position == 0:
40 q_interpolated = q[0]
41 t_interpolated = txyz[0]
42 elif insert_position == len(timestamps):
43 q_interpolated = q[-1]
44 t_interpolated = txyz[-1]
45 else:
46 factor = (timestamp - timestamps[insert_position - 1]) / (timestamps[insert_position] - timestamps[insert_position - 1])
47 q_interpolated = (1 - factor) * q[insert_position - 1] + factor * q[insert_position]
48 t_interpolated = (1 - factor) * txyz[insert_position - 1] + factor * txyz[insert_position]
49 q_interpolated = q_interpolated / np.linalg.norm(q_interpolated)
50 R = quat2rot(q_interpolated[0], q_interpolated[1], q_interpolated[2], q_interpolated[3]).T
51 t = -R @ t_interpolated
52 results[all_files[i]] = {
53 "id": i,
54 "K": K,
55 "R": R,
56 "t": t,
57 "camera_id": 1
58 }
59 return results
60
61def load_tum_camera(dataset_path):
62 results = {}

Callers

nothing calls this directly

Calls 1

quat2rotFunction · 0.70

Tested by

no test coverage detected