-
Notifications
You must be signed in to change notification settings - Fork 15
/
export_gt_pose.py
66 lines (51 loc) · 2.01 KB
/
export_gt_pose.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
from __future__ import absolute_import, division, print_function
import os
import json
import argparse
from utils import readlines
from layers import *
def export_gt_depths_SCARED():
parser = argparse.ArgumentParser(description='export_gt_pose')
parser.add_argument('--data_path',
type=str,
help='path to the root of the KITTI data',
required=True)
parser.add_argument('--split',
type=str,
help='which split to export gt from',
required=True,
choices=["eigen", "eigen_benchmark", "endovis"])
opt = parser.parse_args()
split_folder = os.path.join(os.path.dirname(__file__), "splits", opt.split)
lines = readlines(os.path.join(split_folder, "test_files.txt"))
print("Exporting ground truth depths for {}".format(opt.split))
gt_Ts = []
for line in lines:
folder, frame_id, _ = line.split()
frame_id = int(frame_id)
# pose
f_str_0 = "frame_data{:06d}.json".format(frame_id - 1)
f_str_1 = "frame_data{:06d}.json".format(frame_id)
path_0 = os.path.join(
opt.data_path,
folder,
"image_02/data/frame_data",
f_str_0)
path_1 = os.path.join(
opt.data_path,
folder,
"image_02/data/frame_data",
f_str_1)
with open(path_0, 'r') as path0:
data_0 = json.load(path0)
with open(path_1,'r') as path1:
data_1 = json.load(path1)
data_0 = np.linalg.pinv(np.array(data_0['camera-pose']))
data_1 = np.array(data_1['camera-pose'])
T = (data_1 @ data_0).astype(np.float32)
gt_Ts.append(T)
output_path = os.path.join(split_folder, "gt_poses.npz")
print("Saving to {}".format(opt.split))
np.savez_compressed(output_path, data=np.array(gt_Ts))
if __name__ == "__main__":
export_gt_depths_SCARED()