diff --git a/docs/quickstart/data_conventions.md b/docs/quickstart/data_conventions.md
index a929ff53f..fe7dfe2cb 100644
--- a/docs/quickstart/data_conventions.md
+++ b/docs/quickstart/data_conventions.md
@@ -12,6 +12,10 @@ We use the OpenGL/Blender (and original NeRF) coordinate convention for cameras.
Our world space is oriented such that the up vector is +Z. The XY plane is parallel to the ground plane. In the viewer, you'll notice that red, green, and blue vectors correspond to X, Y, and Z respectively.
+### Pixel coordinates
+
+We assume coordinates correspond to the centers of pixels (e.g. generating a ray for pixel (0,0) will shoot the ray through the center of that pixel). This aligns more with graphics conventions, and is distinct from OpenCV where the corners are aligned with the pixel coordinate.
+
## Dataset format
diff --git a/nerfstudio/data/datamanagers/full_images_datamanager.py b/nerfstudio/data/datamanagers/full_images_datamanager.py
index 38207affb..67ff126db 100644
--- a/nerfstudio/data/datamanagers/full_images_datamanager.py
+++ b/nerfstudio/data/datamanagers/full_images_datamanager.py
@@ -347,6 +347,10 @@ def _undistort_image(
0,
]
)
+ # because OpenCV expects the pixel coord to be top-left, we need to shift the principal point by 0.5
+ # see https://github.com/nerfstudio-project/nerfstudio/issues/3048
+ K[0, 2] = K[0, 2] - 0.5
+ K[1, 2] = K[1, 2] - 0.5
if np.any(distortion_params):
newK, roi = cv2.getOptimalNewCameraMatrix(K, distortion_params, (image.shape[1], image.shape[0]), 0)
image = cv2.undistort(image, K, distortion_params, None, newK) # type: ignore
@@ -367,9 +371,13 @@ def _undistort_image(
mask = torch.from_numpy(mask).bool()
if len(mask.shape) == 2:
mask = mask[:, :, None]
+ newK[0, 2] = newK[0, 2] + 0.5
+ newK[1, 2] = newK[1, 2] + 0.5
K = newK
elif camera.camera_type.item() == CameraType.FISHEYE.value:
+ K[0, 2] = K[0, 2] - 0.5
+ K[1, 2] = K[1, 2] - 0.5
distortion_params = np.array(
[distortion_params[0], distortion_params[1], distortion_params[2], distortion_params[3]]
)
@@ -388,6 +396,8 @@ def _undistort_image(
mask = torch.from_numpy(mask).bool()
if len(mask.shape) == 2:
mask = mask[:, :, None]
+ newK[0, 2] = newK[0, 2] + 0.5
+ newK[1, 2] = newK[1, 2] + 0.5
K = newK
elif camera.camera_type.item() == CameraType.FISHEYE624.value:
fisheye624_params = torch.cat(