-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathexport_gt_depth.py
60 lines (46 loc) · 1.74 KB
/
export_gt_depth.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
from __future__ import absolute_import, division, print_function
import os
import argparse
import numpy as np
import PIL.Image as pil
import cv2
from utils import readlines
def export_gt_depths_SCARED():
parser = argparse.ArgumentParser(description='export_gt_depth')
parser.add_argument('--data_path',
type=str,
help='path to the root of the data',
required=True)
parser.add_argument('--split',
type=str,
help='which split to export gt from',
required=True,
choices=["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))
i=0
gt_depths = []
for line in lines:
i = i+1
folder, frame_id, _ = line.split()
frame_id = int(frame_id)
print(i)
print(folder)
if opt.split == "endovis":
f_str = "scene_points{:06d}.tiff".format(frame_id - 1)
gt_depth_path = os.path.join(
opt.data_path,
folder,
"image_02/data/groundtruth",
f_str)
depth_gt = cv2.imread(gt_depth_path, 3)
depth_gt = depth_gt[:, :, 0]
gt_depth = depth_gt[0:1024, :]
gt_depths.append(gt_depth.astype(np.float32))
output_path = os.path.join(split_folder, "gt_depths.npz")
print("Saving to {}".format(opt.split))
np.savez_compressed(output_path, data=np.array(gt_depths))
if __name__ == "__main__":
export_gt_depths_SCARED()