FilamentCamera::SetProjection(intrinsics, ...) places the principal point half a pixel off for OpenCV-convention intrinsics
Checklist
- I have searched for similar issues.
- For Python issues, I have tested with the latest development wheel.
- I have checked the release documentation and the latest documentation (for
mainbranch).
Describe the issue
SetProjection(const Eigen::Matrix3d& intrinsics, ...) in
cpp/open3d/visualization/rendering/filament/FilamentCamera.cpp maps the principal point to NDC as:
custom_proj[2][0] = 1.0 - 2.0 * intrinsics(0, 2) / width;
custom_proj[2][1] = -1.0 + 2.0 * intrinsics(1, 2) / height;This puts the principal point at NDC 0, the image centre, when cx == width/2. Under the OpenCV convention, where an integer pixel coordinate is the CENTRE of that pixel, the centre of a width-W image is at (W-1)/2, not W/2. So the mapping is half a pixel off for any intrinsic matrix that follows the OpenCV convention, which is where essentially all user calibrations come from.
Open3D's own defaults are OpenCV-convention: PinholeCameraIntrinsicParameters.PrimeSenseDefault is (cx, cy) = (319.5, 239.5) at 640x480, and 319.5 is exactly (W-1)/2. Feeding that intrinsic into the Filament path therefore renders half a pixel off. The legacy GL viewer (ViewControl.cpp) expects the same centre convention.
Note that RaycastingScene::CreateRaysPinhole uses Eigen::Vector3f px(x + 0.5f, y + 0.5f, 1),
i.e. corner-origin, so it is CONSISTENT with the rasteriser. The disagreement is between
Open3D's rendering stack and the OpenCV convention its intrinsics are expressed in, not between
two parts of the rendering stack.
I used Claude Code to write the text for this bug report (and to investigate this further), but I've found & checked the issue myself.
Corroboration from outside Open3D: we hit this in our own renderer, which copied these two lines. Comparing its depth output against a ray caster built directly from the OpenCV intrinsics, and sweeping the ray caster's sampling offset, the best agreement sat at 0.4998 +/- 0.0005 px over nine camera-runs at two resolutions. After adding +0.5 to cx and cy it moved to 0.0004, and the two depth maps then agreed to a median of ~15 nm.
PyTorch3D has the same omission in _cameras_from_opencv_projection, reported in facebookresearch/pytorch3d#1543.
This may be the cause of #5049 ("Why is Open3D's viewer posed slightly incorrectly?", open since 2022, cause never identified), where the reporter sees exactly a small shift between an Open3D render and the undistorted camera image with known pose and intrinsics.
These lines date from "Merge #2731 and #2727 into master (#2762)", Dec 2020.
Steps to reproduce the bug
No rendering is needed to see the arithmetic:
width = 640
cx_opencv_centre = (width - 1) / 2 # 319.5, the OpenCV image centre
ndc = 1.0 - 2.0 * cx_opencv_centre / width
print(ndc) # 0.0015625, not 0.0
The principal point of a centred camera should map to NDC 0. It does so only at cx = 320.0,
which is the corner-origin centre.
To see it in a render, project a known 3D point with the same K and extrinsics using
cv2.projectPoints, then render the same point with OffscreenRenderer.setup_camera(K, T, w, h)
and locate it in the image. The rendered position is half a pixel from the OpenCV projection.Error message
No response
Expected behavior
An intrinsic matrix in the OpenCV convention should render at the position OpenCV's own projection predicts. Concretely, adding 0.5 to the principal point inside the NDC mapping:
custom_proj[2][0] = 1.0 - 2.0 * (intrinsics(0, 2) + 0.5) / width; custom_proj[2][1] = -1.0 + 2.0 * (intrinsics(1, 2) + 0.5) / height;
Alternatively, document that this API expects corner-origin intrinsics, in which case the PrimeSense default and the legacy viewer are inconsistent with it.
Open3D, Python and System information
- Operating system: Windows / Ubuntu 24.04 (WSL)
- Python version: 3.11.13
- Open3D version: 0.19.0
- System architecture: x86_64
- Is this a remote workstation?: no
- How did you install Open3D?: built from source & conda
Note: the source quotes above are from current main, not 0.19.0, and the lines are unchanged between them.Additional information
No response
Source: isl-org/Open3D