11
11
import yaml
12
12
import glob
13
13
import argparse
14
+ import subprocess
14
15
from pathlib import Path
15
16
16
17
import pandas
21
22
logger = logging .getLogger ("benchmark" )
22
23
23
24
# Global settings
25
+ SCRIPT_DIR = os .path .dirname (os .path .abspath (__file__ ))
24
26
DATA_DIR = "/data"
25
- CONFIGS_DIR = "/home/chutsu/projects/proto/benchmark/configs"
27
+ RESOURCE_DIR = f"{ SCRIPT_DIR } /resource"
28
+
29
+ ################################################################################
30
+ # UTILS
31
+ ################################################################################
26
32
27
33
28
34
def docker_command (docker_image , command ):
29
35
""" Form docker command """
30
36
return f"""\
31
- xhost +local:docker; \
32
37
docker run -e DISPLAY \
38
+ --privileged \
33
39
-v /tmp:/tmp \
34
40
-v { DATA_DIR } :{ DATA_DIR } \
35
- -v { CONFIGS_DIR } :/home/docker/configs \
36
- --network="host" \
41
+ -v { RESOURCE_DIR } :/home/docker/resource \
37
42
-it \
38
43
--rm \
39
44
{ docker_image } \
@@ -93,7 +98,12 @@ def dataset_adjust_timestamps(src_dir, dst_dir, dataset_name, calib_file):
93
98
imu_df .to_csv (imu_path , index = False )
94
99
95
100
96
- def run_orbslam3 (mode , ds_path , run_name , calib_file , res_dir , ** kwargs ):
101
+ ################################################################################
102
+ # ORBSLAM3
103
+ ################################################################################
104
+
105
+
106
+ def run_orbslam3 (mode , ds_path , run_name , config_path , res_dir , ** kwargs ):
97
107
""" Run ORBSLAM """
98
108
# Setup
99
109
retries = kwargs .get ("retries" , 3 )
@@ -107,6 +117,14 @@ def run_orbslam3(mode, ds_path, run_name, calib_file, res_dir, **kwargs):
107
117
orbslam3_path = "/home/docker/ORB_SLAM3"
108
118
docker_image = "benchmark/orbslam3"
109
119
120
+ # Check dataset path
121
+ if os .path .exists (ds_path ) is False :
122
+ raise RuntimeError (f"Dataset [{ ds_path } ] does not exist" )
123
+
124
+ # Check calib file
125
+ if os .path .exists (config_path ) is False :
126
+ raise RuntimeError (f"Calibration file [{ config_path } ] does not exist" )
127
+
110
128
# Create a timestamp file for ORBSLAM3
111
129
# -- Get timestamps from camera images
112
130
timestamps = {}
@@ -120,6 +138,14 @@ def run_orbslam3(mode, ds_path, run_name, calib_file, res_dir, **kwargs):
120
138
else :
121
139
timestamps [timestamp ] += 1
122
140
141
+ # -- Check if number of cameras found
142
+ if num_cams == 0 :
143
+ raise RuntimeError (f"Found 0 cameras in [{ ds_path } ]?" )
144
+
145
+ # -- Check number of timestamps
146
+ if len (timestamps ) == 0 :
147
+ raise RuntimeError (f"Found 0 timestamps in [{ ds_path } ]?" )
148
+
123
149
# -- Write out timestamps to file
124
150
timestamps_file = open (timestamps_path , "w" )
125
151
for timestamp , count in timestamps .items ():
@@ -132,81 +158,109 @@ def run_orbslam3(mode, ds_path, run_name, calib_file, res_dir, **kwargs):
132
158
run_cmd = f"""\
133
159
{ orbslam3_path } /Examples/Monocular/mono_euroc \
134
160
{ orbslam3_path } /Vocabulary/ORBvoc.txt \
135
- { calib_file } \
161
+ { config_path } \
136
162
{ ds_path } \
137
163
{ timestamps_path } \
138
164
dataset-{ uuid_str } -{ run_name } _mono"""
139
165
cmd = docker_command (docker_image , run_cmd )
140
166
f_file = f"f_dataset-{ uuid_str } -{ run_name } _mono.txt"
141
167
kf_file = f"kf_dataset-{ uuid_str } -{ run_name } _mono.txt"
142
168
143
- # elif mode == "stereo":
144
- # run_cmd = f"""\
145
- # {orbslam3_path}/Examples/Stereo/stereo_euroc \
146
- # {orbslam3_path}/Vocabulary/ORBvoc.txt \
147
- # {calib_file } \
148
- # {ds_path} \
149
- # {timestamps_path} \
150
- # dataset-{uuid_str}-{run_name}_stereo"""
151
- # cmd = docker_command(docker_image, run_cmd)
152
- # f_file = f"f_dataset-{uuid_str}-{run_name}_stereo.txt"
153
- # kf_file = f"kf_dataset-{uuid_str}-{run_name}_stereo.txt"
154
- #
155
- # elif mode == "stereo_imu":
156
- # run_cmd = f"""\
157
- # {orbslam3_path}/Examples/Stereo-Inertial/stereo_inertial_euroc \
158
- # {orbslam3_path}/Vocabulary/ORBvoc.txt \
159
- # {calib_file } \
160
- # {ds_path} \
161
- # {timestamps_path} \
162
- # dataset-{uuid_str}-{run_name}_stereo_imu"""
163
- # cmd = docker_command(docker_image, run_cmd)
164
- # f_file = f"f_dataset-{uuid_str}-{run_name}_stereo_imu.txt"
165
- # kf_file = f"kf_dataset-{uuid_str}-{run_name}_stereo_imu.txt"
166
- # else:
167
- # logger.error("ERROR! ORBSLAM3 [%s] mode not supported!", mode)
168
- # sys.exit(-1)
169
- #
170
- # # Check if results already exists
171
- # f_dst = Path(res_dir, f_file.replace(f"-{uuid_str}", ""))
172
- # kf_dst = Path(res_dir, kf_file.replace(f"-{uuid_str}", ""))
173
- # if os.path.exists(f_dst) or os.path.exists(kf_dst):
174
- # return True
169
+ elif mode == "stereo" :
170
+ run_cmd = f"""\
171
+ { orbslam3_path } /Examples/Stereo/stereo_euroc \
172
+ { orbslam3_path } /Vocabulary/ORBvoc.txt \
173
+ { config_path } \
174
+ { ds_path } \
175
+ { timestamps_path } \
176
+ dataset-{ uuid_str } -{ run_name } _stereo"""
177
+ cmd = docker_command (docker_image , run_cmd )
178
+ f_file = f"f_dataset-{ uuid_str } -{ run_name } _stereo.txt"
179
+ kf_file = f"kf_dataset-{ uuid_str } -{ run_name } _stereo.txt"
180
+
181
+ elif mode == "stereo_imu" :
182
+ run_cmd = f"""\
183
+ { orbslam3_path } /Examples/Stereo-Inertial/stereo_inertial_euroc \
184
+ { orbslam3_path } /Vocabulary/ORBvoc.txt \
185
+ { config_path } \
186
+ { ds_path } \
187
+ { timestamps_path } \
188
+ dataset-{ uuid_str } -{ run_name } _stereo_imu"""
189
+ cmd = docker_command (docker_image , run_cmd )
190
+ f_file = f"f_dataset-{ uuid_str } -{ run_name } _stereo_imu.txt"
191
+ kf_file = f"kf_dataset-{ uuid_str } -{ run_name } _stereo_imu.txt"
192
+ else :
193
+ logger .error ("ERROR! ORBSLAM3 [%s] mode not supported!" , mode )
194
+ sys .exit (- 1 )
195
+
196
+ # Check if results already exists
197
+ f_dst = Path (res_dir , f_file .replace (f"-{ uuid_str } " , "" ))
198
+ kf_dst = Path (res_dir , kf_file .replace (f"-{ uuid_str } " , "" ))
199
+ if os .path .exists (f_dst ) or os .path .exists (kf_dst ):
200
+ return True
175
201
176
202
# Run
177
- # for _ in range(retries):
178
- # # Run ORBSLAM3
179
- # time.sleep(2)
180
- # # print(f"{cmd}")
181
- # os.system(cmd)
182
- #
183
- # # Check if result files exists
184
- # if os.path.exists(f_file) is False:
185
- # logger.error("ERROR! [%s] DOES NOT EXIST! RETRYING!", f_file)
186
- # continue
187
- # if os.path.exists(kf_file) is False:
188
- # logger.error("ERROR! [%s] DOES NOT EXIST! RETRYING!", kf_file)
189
- # continue
190
- #
191
- # # Move results
192
- # os.system(f"mv {f_file} {f_dst}")
193
- # os.system(f"rm {kf_file}") # Remove (not useful for evaluation)
194
- # return True
195
- #
196
- # # Failed to run orbslam
197
- # logger.error("FAILED TO RUN ORBSLAM")
198
- # logger.error("COMMAND:")
199
- # logger.error("%s\n", cmd)
200
- # return False
203
+ for _ in range (retries ):
204
+ # Run ORBSLAM3
205
+ time .sleep (2 )
206
+ result = subprocess .run (cmd .split ())
207
+
208
+ # Check if result files exists
209
+ if os .path .exists (f_file ) is False :
210
+ logger .error ("ERROR! [%s] DOES NOT EXIST! RETRYING!" , f_file )
211
+ continue
212
+ if os .path .exists (kf_file ) is False :
213
+ logger .error ("ERROR! [%s] DOES NOT EXIST! RETRYING!" , kf_file )
214
+ continue
215
+
216
+ # Move results
217
+ os .system (f"mv { f_file } { f_dst } " )
218
+ os .system (f"rm { kf_file } " ) # Remove (not useful for evaluation)
219
+ return True
201
220
221
+ # Failed to run orbslam
222
+ logger .error ("FAILED TO RUN ORBSLAM" )
223
+ logger .error ("COMMAND:" )
224
+ logger .error ("%s\n " , cmd )
225
+ return False
202
226
203
- def run_vins_fusion (mode , ds_path , run_name , calib_file , output , ** kwargs ):
227
+
228
+ def run_orbslam3_euroc (run_name , mode , config_path , res_dir , ** kwargs ):
229
+ """Run OBSLAM3 on EuRoC dataset"""
230
+ data_dir = kwargs .get ("data_dir" , "/data/euroc" )
231
+ sequences = kwargs .get ("sequences" , [
232
+ "MH_01" ,
233
+ "MH_02" ,
234
+ "MH_03" ,
235
+ "MH_04" ,
236
+ "MH_05" ,
237
+ "V1_01" ,
238
+ "V1_02" ,
239
+ "V1_03" ,
240
+ "V2_01" ,
241
+ "V2_02" ,
242
+ "V2_03" ,
243
+ ])
244
+ for seq in sequences :
245
+ run_orbslam3 (mode , f"{ data_dir } /{ seq } " , run_name , config_path , res_dir )
246
+
247
+
248
+ ################################################################################
249
+ # VINS-FUSION
250
+ ################################################################################
251
+
252
+
253
+ def run_vins_fusion (mode , ds_path , run_name , config_path , output , ** kwargs ):
204
254
""" Run VINS-Fusion """
205
255
# Setup
206
256
retries = kwargs .get ("retries" , 3 )
207
257
docker_image = kwargs .get ("docker_image" , "benchmark/vins-fusion" )
208
258
uuid_str = str (uuid .uuid4 ())
209
259
260
+ # Check dataset path
261
+ if os .path .exists (ds_path ) is False :
262
+ raise RuntimeError (f"Dataset [{ ds_path } ] does not exist" )
263
+
210
264
# Run VINS-Fusion
211
265
ds_dir = os .path .dirname (ds_path )
212
266
est_path = f"{ ds_dir } /vins-fusion-estimation-{ uuid_str } .bag"
@@ -217,7 +271,7 @@ def run_vins_fusion(mode, ds_path, run_name, calib_file, output, **kwargs):
217
271
roslaunch configs/vins-fusion/vins-fusion.launch \
218
272
rosbag_input_path:={ ds_path } \
219
273
rosbag_output_path:={ est_path } \
220
- config_file:={ calib_file } """
274
+ config_file:={ config_path } """
221
275
cmd = docker_command (docker_image , run_cmd )
222
276
223
277
else :
@@ -247,7 +301,12 @@ def run_vins_fusion(mode, ds_path, run_name, calib_file, output, **kwargs):
247
301
return False
248
302
249
303
250
- def run_okvis (mode , ds_path , run_name , calib_file , output , ** kwargs ):
304
+ ################################################################################
305
+ # OKVIS
306
+ ################################################################################
307
+
308
+
309
+ def run_okvis (mode , ds_path , run_name , config_path , output , ** kwargs ):
251
310
""" Run OKVIS """
252
311
# Setup
253
312
retries = kwargs .get ("retries" , 3 )
@@ -258,7 +317,7 @@ def run_okvis(mode, ds_path, run_name, calib_file, output, **kwargs):
258
317
ds_dir = os .path .dirname (ds_path )
259
318
cmd = ""
260
319
if mode in ["stereo_imu" ]:
261
- run_cmd = f"okvis_app_synchronous { calib_file } { ds_path } "
320
+ run_cmd = f"okvis_app_synchronous { config_path } { ds_path } "
262
321
cmd = docker_command (docker_image , run_cmd )
263
322
264
323
else :
@@ -275,12 +334,16 @@ def run_okvis(mode, ds_path, run_name, calib_file, output, **kwargs):
275
334
return True
276
335
277
336
# Failed to run orbslam
278
- logger .error ("FAILED TO RUN VINS-Fusion " )
337
+ logger .error ("FAILED TO RUN OKVIS " )
279
338
logger .error ("COMMAND:" )
280
339
logger .error ("%s\n " , cmd )
281
340
return False
282
341
283
342
343
+ ################################################################################
344
+ # MAIN
345
+ ################################################################################
346
+
284
347
if __name__ == "__main__" :
285
348
# # Parse command line arguments
286
349
# prog_name = "benchmark"
@@ -313,6 +376,6 @@ def run_okvis(mode, ds_path, run_name, calib_file, output, **kwargs):
313
376
mode = "mono"
314
377
dataset = "/data/euroc/MH_01"
315
378
run_name = "euroc-mh01-mono"
316
- config = "./configs/orbslam3/euroc/euroc-mono.yaml"
379
+ config = "./resource/ configs/orbslam3/euroc/euroc-mono.yaml"
317
380
output = "/data/orbslam3-exp"
318
381
run_orbslam3 (mode , dataset , run_name , config , output )
0 commit comments