forked from nianticlabs/ace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-ace-dataset-train-from-cvsl-record.py
55 lines (42 loc) · 1.67 KB
/
create-ace-dataset-train-from-cvsl-record.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
#!/usr/bin/env python
import csv
from scipy.spatial.transform import Rotation as R
import numpy as np
import shutil
import os
# -----------------------------------------------------------------------------
# Copy PoseID file (from cvsl_example_tracking) into root directory of the CVSL recording!
# Needed files and directories in record folder:
# cam0.txt
# cam0
# PoseID
# Set focal length as provided in config.yaml!
focal_length = 426
# -----------------------------------------------------------------------------
# Create directories
if not os.path.exists("ace-dataset/train/poses"):
os.makedirs("ace-dataset/train/poses")
if not os.path.exists("ace-dataset/train/rgb"):
os.makedirs("ace-dataset/train/rgb")
if not os.path.exists("ace-dataset/train/calibration"):
os.makedirs("ace-dataset/train/calibration")
# Get image filenames
images = open('cam0.txt', 'r')
im_filenames = [row[1] for row in csv.reader(images, delimiter=' ')]
with open ('PoseID', 'r') as f:
for row in csv.reader(f, delimiter=' '):
id = row[0]
qx = row[4]
qy = row[5]
qz = row[6]
qw = row[7]
T = np.eye(4, dtype=float)
T[:3, :3] = R.from_quat([qx, qy, qz, qw]).as_matrix()
T[0, 3] = row[1]
T[1, 3] = row[2]
T[2, 3] = row[3]
np.savetxt("ace-dataset/train/poses/seq-01-frame-" + id + ".txt", T, delimiter=" ", fmt='%.10f')
shutil.copy2(im_filenames[int(id)], "ace-dataset/train/rgb/seq-01-frame-" + id + ".color.png")
calibration_file = open("ace-dataset/train/calibration/seq-01-frame-" + id + ".txt", "w")
calibration_file.write(str(focal_length))
calibration_file.close()