Skip to content

Commit

Permalink
Improve mesh and point cloud output modes (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaatrasa authored Apr 25, 2024
1 parent 6b22103 commit 074bdde
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions python/cli/process/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def define_args(parser):
parser.add_argument('--blur_filter_range', type=int, default=4, help='Remove key frames that are the blurriest in a neighborhood of this size (0=disabled)')
parser.add_argument('--no_undistort', action='store_true', help='Do not undistort output images (only supported with certain devices)')
parser.add_argument('--image_format', type=str, default='jpg', help="Color image format (use 'png' for top quality)")
parser.add_argument("--texturize", help="Add textures to mesh export (BETA)", action="store_true")
parser.add_argument("--preview", help="Show latest primary image as a preview", action="store_true")
parser.add_argument("--preview3d", help="Show 3D visualization", action="store_true")
return parser
Expand Down Expand Up @@ -349,7 +350,7 @@ def post_process_point_clouds(globalPointCloud, sparse_point_cloud_df):

return merged_df

def processMappingOutput(output):
def process_mapping_output(output):
nonlocal savedKeyFrames
nonlocal pointClouds
nonlocal sparsePointColors
Expand Down Expand Up @@ -602,7 +603,7 @@ def write_colmap_csv(data, fn):

finalMapWritten = True

def onVioOutput(vioOutput):
def on_vio_output(vioOutput):
nonlocal visualizer, isTracking
wasTracking = isTracking
isTracking = vioOutput.status == spectacularAI.TrackingStatus.TRACKING
Expand All @@ -612,12 +613,22 @@ def onVioOutput(vioOutput):
if visualizer is not None:
visualizer.onVioOutput(vioOutput.getCameraPose(0), status=vioOutput.status)

def onMappingOutput(output):
def on_mapping_output(output):
try:
processMappingOutput(output)
process_mapping_output(output)
except Exception as e:
print(f"ERROR: {e}", flush=True)
raise e
raise

def is_already_rectified(input_dir):
vioConfigYaml = f"{input_dir}/vio_config.yaml"
if os.path.exists(vioConfigYaml):
with open(vioConfigYaml) as file:
for line in file:
if "alreadyRectified" in line:
_, value = line.split(":")
return value.lower().strip() == "true"
return False

def parse_input_dir(input_dir):
cameras = None
Expand Down Expand Up @@ -661,9 +672,11 @@ def parse_input_dir(input_dir):
tmp_dir = None
if args.format in ['ply', 'pcd']:
config["mapSavePath"] = args.output
parameter_sets.append('point-cloud')
elif args.format == 'obj':
assert not args.mono
config['recMeshSavePath'] = args.output
config['recTexturize'] = args.texturize
parameter_sets.append('meshing')
else:
# Clear output dir
Expand Down Expand Up @@ -717,10 +730,9 @@ def parse_input_dir(input_dir):
if prefer_icp:
parameter_sets.extend(['icp', 'realsense-icp'])
if not args.fast: parameter_sets.append('offline-icp')
config['stereoPointCloudStride'] = 15
elif device_preset == 'oak-d':
config['stereoPointCloudMinDepth'] = 0.5
config['stereoPointCloudStride'] = 30
config['alreadyRectified'] = is_already_rectified(args.input) # rectification required for stereo point cloud
elif device_preset is not None and "orbbec" in device_preset:
if prefer_icp:
parameter_sets.extend(['icp'])
Expand All @@ -736,8 +748,8 @@ def parse_input_dir(input_dir):
config['parameterSets'] = parameter_sets
print(config)

replay = spectacularAI.Replay(args.input, mapperCallback = onMappingOutput, configuration = config, ignoreFolderConfiguration = True)
replay.setOutputCallback(onVioOutput)
replay = spectacularAI.Replay(args.input, mapperCallback = on_mapping_output, configuration = config, ignoreFolderConfiguration = True)
replay.setOutputCallback(on_vio_output)

try:
if visualizer is None:
Expand Down

0 comments on commit 074bdde

Please sign in to comment.