forked from CathIAS/TLIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEuRoC_toTLIO_transform.py
208 lines (177 loc) · 8.59 KB
/
EuRoC_toTLIO_transform.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import numpy as np
import os
import json
import math
def interp_xyz(time, opt_time, xyz):
interp_x = np.interp(time, xp=opt_time, fp=xyz[:, 0])
interp_y = np.interp(time, xp=opt_time, fp=xyz[:, 1])
interp_z = np.interp(time, xp=opt_time, fp=xyz[:, 2])
interp_xyz = np.stack([interp_x, interp_y, interp_z]).transpose()
return interp_xyz
def interp_quat(time, opt_time, xyzw):
interp_x = np.interp(time, xp=opt_time, fp=xyzw[:, 0])
interp_y = np.interp(time, xp=opt_time, fp=xyzw[:, 1])
interp_z = np.interp(time, xp=opt_time, fp=xyzw[:, 2])
interp_w = np.interp(time, xp=opt_time, fp=xyzw[:, 3])
interp_xyzw = np.stack([interp_x, interp_y, interp_z, interp_w]).transpose()
return interp_xyzw
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--EuRoC_path', type=str, default='local_data/EuRoc_dataset',
help='path to the EuRoC dataset')
parser.add_argument('--transformed_path', type=str, default='local_data/EuRoc_transformed',
help='path to the transformed EuRoC dataset')
args = parser.parse_args()
EuRoc_path = args.EuRoC_path
transformed_path = args.transformed_path
if not os.path.exists(transformed_path):
os.makedirs(transformed_path)
for root, subsets, files in os.walk(EuRoc_path):
for subset in subsets:
if not subset.startswith("MH") and not subset.startswith("V"):
continue
subset_path = os.path.join(EuRoc_path, subset)
if not os.path.exists(os.path.join(transformed_path, subset)):
os.makedirs(os.path.join(transformed_path, subset))
raw_data_path = os.path.join(subset_path, "mav0", "imu0", "data.csv")
raw_IMUdata = np.loadtxt(raw_data_path, delimiter=',')
raw_rows = np.size(raw_IMUdata, axis=0)
raw_cols = np.size(raw_IMUdata, axis=1)
imu0_samples_rows = raw_rows
imu0_samples_cols = raw_cols + 1
imu0_samples = np.zeros((imu0_samples_rows, imu0_samples_cols), dtype=np.float64)
imu0_samples[:, 0] = raw_IMUdata[:, 0]
imu0_samples[:, 1] = 0
imu0_samples[:, 2:imu0_samples_cols] = raw_IMUdata[:, 1:raw_cols]
np.savetxt(os.path.join(transformed_path, subset, "imu_samples_0.csv"), imu0_samples, delimiter=",",
header="timestamp [ns], temperature [degC], w_RS_S_x [rad s^-1], w_RS_S_y [rad s^-1],"
" w_RS_S_z [rad s^-1], a_RS_S_x [m s^-2], a_RS_S_y [m s^-2], a_RS_S_z [m s^-2]")
gt_file_path = os.path.join(subset_path, "mav0", 'state_groundtruth_estimate0', 'data.csv')
gt_data = np.loadtxt(gt_file_path, delimiter=',')
t_start = np.max([raw_IMUdata[0, 0], gt_data[0, 0]])
t_end = np.min([raw_IMUdata[-1, 0], gt_data[-1, 0]])
index_t_start_raw = np.searchsorted(raw_IMUdata[:, 0], t_start)
index_t_end_raw = np.searchsorted(raw_IMUdata[:, 0], t_end, side='right')
index_t_start_gt = np.searchsorted(gt_data[:, 0], t_start)
index_t_end_gt = np.searchsorted(gt_data[:, 0], t_end, 'right')
calibrated_rows_gt = index_t_end_gt - index_t_start_gt
calibrated_rows_raw = index_t_end_raw - index_t_start_raw
calibrated_cols = 17
imu0_resampled = np.zeros((calibrated_rows_gt, calibrated_cols), dtype=np.float64)
imu0_resampled[:, 0] = np.trunc(gt_data[index_t_start_gt:index_t_end_gt, 0] / 1e3)
if calibrated_rows_raw == calibrated_rows_gt:
imu0_resampled[:, 1:4] = raw_IMUdata[index_t_start_raw:index_t_end_raw, 1:4]
imu0_resampled[:, 4:7] = raw_IMUdata[index_t_start_raw:index_t_end_raw, 4:7]
else:
imu0_resampled[:, 1:4] = interp_xyz(gt_data[index_t_start_gt:index_t_end_gt, 0],
raw_IMUdata[index_t_start_raw:index_t_end_raw, 0],
raw_IMUdata[index_t_start_raw:index_t_end_raw, 1:4])
imu0_resampled[:, 4:7] = interp_xyz(gt_data[index_t_start_gt:index_t_end_gt, 0],
raw_IMUdata[index_t_start_raw:index_t_end_raw, 0],
raw_IMUdata[index_t_start_raw:index_t_end_raw, 4:7])
imu0_resampled[:, 7:10] = gt_data[:, 5:8]
imu0_resampled[:, 10] = gt_data[:, 4]
imu0_resampled[:, 11:14] = gt_data[:, 1:4]
imu0_resampled[:, 14:17] = gt_data[:, 8:11]
np.save(os.path.join(transformed_path, subset, "imu0_resampled.npy"), imu0_resampled)
imu0_resampled_description = {
"columns_name(width)": [
"ts_us(1)",
"gyr_compensated_rotated_in_World(3)",
"acc_compensated_rotated_in_World(3)",
"qxyzw_World_Device(4)",
"pos_World_Device(3)",
"vel_World(3)"
],
"num_rows": calibrated_rows_gt.item(),
"approximate_frequency_hz": 200.0,
"t_start_us": float(imu0_resampled[0, 0]),
"t_end_us": float(imu0_resampled[-1, 0])
}
with open(os.path.join(transformed_path, subset, "imu0_resampled_description.json"), "w") as file:
json.dump(imu0_resampled_description, file, indent=4)
with open(os.path.join(transformed_path, subset, "calibration.json"), "w") as file:
calibration_info = {
"Accelerometer": {
"Bias": {
"Name": "Constant",
"Offset": [
0.0,
0.0,
0.0
]
},
"Model": {
"Name": "Linear",
"RectificationMatrix": [
[
1.0,
0.0,
0.0
],
[
0.0,
1.0,
0.0
],
[
0.0,
0.0,
1.0
]
]
},
"TimeOffsetSec_Device_Accel": 0.0
},
"Calibrated": True,
"Gyroscope": {
"Bias": {
"Name": "Constant",
"Offset": [
0.0,
0.0,
0.0
]
},
"Model": {
"Name": "Linear",
"RectificationMatrix": [
[
1.0,
0.0,
0.0
],
[
0.0,
1.0,
0.0
],
[
0.0,
0.0,
1.0
]
]
},
"TimeOffsetSec_Device_Gyro": 0.0
},
"Label": "unlabeled_imu_0",
"SerialNumber": "rift://",
"T_Device_Imu": {
"Translation": [
0.0,
0.0,
0.0
],
"UnitQuaternion": [
1.0,
[
0.0,
0.0,
0.0
]
]
}
}
json.dump(calibration_info, file, indent=4)