From 38726da2190780c2a2205449dfac5d9ae98136e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Kulh=C3=A1nek?= Date: Wed, 29 Nov 2023 20:48:41 +0100 Subject: [PATCH] Fix tangential camera distortion (p1,p2 in opencv camera) (#2627) --- nerfstudio/cameras/cameras.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nerfstudio/cameras/cameras.py b/nerfstudio/cameras/cameras.py index 68f7b186f..c1b988dbb 100644 --- a/nerfstudio/cameras/cameras.py +++ b/nerfstudio/cameras/cameras.py @@ -615,9 +615,9 @@ class Cameras(TensorDataclass): # Get our image coordinates and image coordinates offset by 1 (offsets used for dx, dy calculations) # Also make sure the shapes are correct - coord = torch.stack([(x - cx) / fx, -(y - cy) / fy], -1) # (num_rays, 2) - coord_x_offset = torch.stack([(x - cx + 1) / fx, -(y - cy) / fy], -1) # (num_rays, 2) - coord_y_offset = torch.stack([(x - cx) / fx, -(y - cy + 1) / fy], -1) # (num_rays, 2) + coord = torch.stack([(x - cx) / fx, (y - cy) / fy], -1) # (num_rays, 2) + coord_x_offset = torch.stack([(x - cx + 1) / fx, (y - cy) / fy], -1) # (num_rays, 2) + coord_y_offset = torch.stack([(x - cx) / fx, (y - cy + 1) / fy], -1) # (num_rays, 2) assert ( coord.shape == num_rays_shape + (2,) and coord_x_offset.shape == num_rays_shape + (2,) @@ -648,6 +648,9 @@ class Cameras(TensorDataclass): distortion_params[mask, :], ).reshape(-1, 2) + # Switch from OpenCV to OpenGL + coord_stack[..., 1] *= -1 + # Make sure after we have undistorted our images, the shapes are still correct assert coord_stack.shape == (3,) + num_rays_shape + (2,)