Skip to content

Incorrect handling of distortion parameters in colmap.py #794

@MomokoMatsuo

Description

@MomokoMatsuo

Currently, distortion parameters are read as follows:

# Get distortion parameters.
type_ = cam.model
if type_ == CameraModelId.SIMPLE_PINHOLE:
    params = np.empty(0, dtype=np.float32)
    camtype = "perspective"
elif type_ == CameraModelId.PINHOLE:
    params = np.empty(0, dtype=np.float32)
    camtype = "perspective"
if type_ == CameraModelId.SIMPLE_RADIAL:
    params = np.array([cam.params[4], 0.0, 0.0, 0.0], dtype=np.float32)
    camtype = "perspective"
elif type_ == CameraModelId.RADIAL:
    params = np.array([cam.params[4], cam.params[5], 0.0, 0.0], dtype=np.float32)
    camtype = "perspective"
elif type_ == CameraModelId.OPENCV:
    params = np.array([cam.params[4], cam.params[5], cam.params[6], cam.params[7]], dtype=np.float32)
    camtype = "perspective"
elif type_ == CameraModelId.OPENCV_FISHEYE:
    params = np.array([cam.params[4], cam.params[5], cam.params[6], cam.params[7]], dtype=np.float32)
    camtype = "fisheye"
assert (
    camtype == "perspective" or camtype == "fisheye"
), f"Only perspective and fisheye cameras are supported, got {type_}"

However, the indexing of cam.params is incorrect.
For example, in COLMAP’s camera models (see [colmap/models.h](https://github.com/colmap/colmap/blob/main/src/colmap/sensor/models.h)):

SimpleRadialCameraModel: f, cx, cy, k1, k2
RadialCameraModel: fx, fy, cx, cy, k1, k2, p1, p2
OpenCVCameraModel: fx, fy, cx, cy, k1, k2, k3, k4
OpenCVFisheyeCameraModel: fx, fy, cx, cy, k1, k2, p1, p2, k3, k4, k5, k6

This means, for example, that in SIMPLE_RADIAL, the correct index for k1 should be cam.params[3], not cam.params[4].
In general, except for SIMPLE_PINHOLE, all current models appear to be shifted by one index.

I searched the repository to check if this issue was already reported, but I could not find anything. Apologies if it has already been addressed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions