Skip to content

Commit

Permalink
Handle uncalibrated Metashape sensor (nerfstudio-project#1359)
Browse files Browse the repository at this point in the history
This fix allows loading Metashape XML files which
contain an additional uncalibrated sensor.

Metashape XML format keeps unmatched images but
assignes a dummy sensor to them. The sensor has
no calibration data.

Co-authored-by: gilureta <gilureta@amazon.com>
  • Loading branch information
gilureta and gilureta authored Feb 6, 2023
1 parent 827417c commit 5fe1ccf
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions nerfstudio/process_data/metashape_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ def metashape_to_json( # pylint: disable=too-many-statements
sensors = chunk.find("sensors")

# TODO Add support for per-frame intrinsics
if sensors is None or len(sensors) != 1:
if sensors is None:
raise ValueError("No sensors found")

calibrated_sensors = [sensor for sensor in sensors if sensor.find("calibration")]
if len(calibrated_sensors) != 1:
raise ValueError("Only one sensor is supported for now")

sensor = sensors.find("sensor")
sensor = calibrated_sensors[0]

data = {}

Expand Down Expand Up @@ -98,6 +102,14 @@ def metashape_to_json( # pylint: disable=too-many-statements
if camera_label not in image_filename_map:
continue
frame["file_path"] = image_filename_map[camera_label].as_posix()

if camera.get("sensor_id") != sensor.get("id"):
# this should only happen when we have a sensor that doesn't have calibration
if verbose:
CONSOLE.print(f"Missing sensor calibration for {camera.get('label')}, Skipping")
num_skipped += 1
continue

if camera.find("transform") is None:
if verbose:
CONSOLE.print(f"Missing transforms data for {camera.get('label')}, Skipping")
Expand Down

0 comments on commit 5fe1ccf

Please sign in to comment.