@@ -295,11 +295,13 @@ def process(args):
295
295
import numpy as np
296
296
import pandas as pd
297
297
298
+ PC_AND_MESH_FORMATS = ['ply' , 'pcd' , 'obj' ]
299
+
298
300
# Overwrite format if output is set to pointcloud
299
- if args . output . endswith ( ".ply" ) :
300
- args .format = "ply"
301
- elif args .output . endswith ( ".pcd" ):
302
- args . format = "pcd"
301
+ for fmt in PC_AND_MESH_FORMATS :
302
+ if args .output . endswith ( '.' + fmt ):
303
+ args .format = fmt
304
+ break
303
305
304
306
useMono = None
305
307
@@ -362,7 +364,9 @@ def processMappingOutput(output):
362
364
if visualizer is not None :
363
365
visualizer .onMappingOutput (output )
364
366
365
- if args .format in ['ply' , 'pcd' ]:
367
+ saveImages = True
368
+ if args .format in PC_AND_MESH_FORMATS :
369
+ saveImages = False
366
370
if output .finalMap : finalMapWritten = True
367
371
return
368
372
@@ -396,8 +400,9 @@ def processMappingOutput(output):
396
400
img = undistortedFrame .image .toArray ()
397
401
398
402
bgrImage = cv2 .cvtColor (img , cv2 .COLOR_RGB2BGR )
399
- fileName = f"{ tmp_dir } /frame_{ frameId :05} .{ args .image_format } "
400
- cv2 .imwrite (fileName , bgrImage )
403
+ if saveImages :
404
+ fileName = f"{ tmp_dir } /frame_{ frameId :05} .{ args .image_format } "
405
+ cv2 .imwrite (fileName , bgrImage )
401
406
402
407
# Find colors for sparse features
403
408
SHOW_FEATURE_MARKERS = True
@@ -440,8 +445,9 @@ def processMappingOutput(output):
440
445
if frameSet .depthFrame is not None and frameSet .depthFrame .image is not None and not useMono :
441
446
alignedDepth = frameSet .getAlignedDepthFrame (undistortedFrame )
442
447
depthData = alignedDepth .image .toArray ()
443
- depthFrameName = f"{ tmp_dir } /depth_{ frameId :05} .png"
444
- cv2 .imwrite (depthFrameName , depthData )
448
+ if saveImages :
449
+ depthFrameName = f"{ tmp_dir } /depth_{ frameId :05} .png"
450
+ cv2 .imwrite (depthFrameName , depthData )
445
451
446
452
DEPTH_PREVIEW = False
447
453
if args .preview and DEPTH_PREVIEW :
@@ -650,14 +656,20 @@ def parse_input_dir(input_dir):
650
656
"icpVoxelSize" : min (args .key_frame_distance , 0.1 )
651
657
}
652
658
659
+ parameter_sets = ['wrapper-base' ]
660
+
661
+ tmp_dir = None
653
662
if args .format in ['ply' , 'pcd' ]:
654
663
config ["mapSavePath" ] = args .output
664
+ elif args .format == 'obj' :
665
+ assert not args .mono
666
+ config ['recMeshSavePath' ] = args .output
667
+ parameter_sets .append ('meshing' )
655
668
else :
656
669
# Clear output dir
657
670
shutil .rmtree (f"{ args .output } /images" , ignore_errors = True )
658
671
os .makedirs (f"{ args .output } /images" , exist_ok = True )
659
-
660
- tmp_dir = tempfile .mkdtemp ()
672
+ tmp_dir = tempfile .mkdtemp ()
661
673
662
674
device_preset , cameras = parse_input_dir (args .input )
663
675
@@ -673,7 +685,6 @@ def parse_input_dir(input_dir):
673
685
if useMono : config ['useStereo' ] = False
674
686
675
687
prefer_icp = not args .no_icp and not useMono
676
- parameter_sets = ['wrapper-base' ]
677
688
678
689
if not args .fast :
679
690
parameter_sets .append ('offline-base' )
@@ -741,10 +752,11 @@ def parse_input_dir(input_dir):
741
752
742
753
replay = None
743
754
744
- try :
745
- shutil .rmtree (tmp_dir )
746
- except :
747
- print (f"Failed to clean temporary directory, you can delete these files manually, they are no longer required: { tmp_dir } " , flush = True )
755
+ if tmp_dir is not None :
756
+ try :
757
+ shutil .rmtree (tmp_dir )
758
+ except :
759
+ print (f"Failed to clean temporary directory, you can delete these files manually, they are no longer required: { tmp_dir } " , flush = True )
748
760
749
761
if not finalMapWritten :
750
762
print ('Mapping failed: no output generated' )
0 commit comments