Incorrect tangential distortion parameter mapping in Metashape import
Describe the bug
The Metashape import functionality in nerfstudio incorrectly maps tangential distortion parameters p1 and p2, leading to incorrect camera distortion when importing Metashape projects.
Root Cause
Metashape and OpenCV use different conventions for tangential distortion parameters:
OpenCV convention (used by nerfstudio):
x_distorted = x + [2*p1*x*y + p2*(r² + 2*x²)]
y_distorted = y + [2*p2*x*y + p1*(r² + 2*y²)]
Metashape convention:
x_distorted = x + [2*p2*x*y + p1*(r² + 2*x²)]
y_distorted = y + [2*p1*x*y + p2*(r² + 2*y²)]
The parameters are swapped between the two systems:
- Metashape
p1= OpenCVp2 - Metashape
p2= OpenCVp1
Current Bug
In nerfstudio/process_data/metashape_utils.py lines 113-114:
s["p1"] = findparam(calib, "p1") # Should be p2
s["p2"] = findparam(calib, "p2") # Should be p1
This directly copies the parameters without accounting for the convention difference.
Fix
The parameters should be swapped during import:
s["p1"] = findparam(calib, "p2") # Use Metashape's p2 for OpenCV's p1
s["p2"] = findparam(calib, "p1") # Use Metashape's p1 for OpenCV's p2
Reference
This issue was identified and discussed in the EyefulTower project: https://github.com/facebookresearch/EyefulTower/issues/7#issuecomment-2662520442
@couperle
Impact
This bug affects the accuracy of camera calibration for any nerfstudio project imported from Metashape that uses tangential distortion correction, potentially leading to reduced reconstruction quality.