mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-18 22:04:02 +08:00
shift principle points by .5 in undistortion (#3071)
* shift principle points by .5 * fix ordering * add fisheye offset
This commit is contained in:
1 parent
c302cc5301
commit
a64026f8db
2 files changed
+14
No files matched your search
@@ -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.
|
||||
|
||||
<hr>
|
||||
|
||||
## Dataset format
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user