Fix tangential camera distortion (p1,p2 in opencv camera) (#2627)

This commit is contained in:
Jonáš Kulhánek authored and GitHub committed 2023-11-29 19:48:41 +00:00
1 parent c896ee4e0a
commit 38726da219
1 file changed
+6 -3
+6 -3
View File
@@ -615,9 +615,9 @@ class Cameras(TensorDataclass):
# Get our image coordinates and image coordinates offset by 1 (offsets used for dx, dy calculations) # Get our image coordinates and image coordinates offset by 1 (offsets used for dx, dy calculations)
# Also make sure the shapes are correct # Also make sure the shapes are correct
coord = torch.stack([(x - cx) / fx, -(y - cy) / 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_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_y_offset = torch.stack([(x - cx) / fx, (y - cy + 1) / fy], -1) # (num_rays, 2)
assert ( assert (
coord.shape == num_rays_shape + (2,) coord.shape == num_rays_shape + (2,)
and coord_x_offset.shape == num_rays_shape + (2,) and coord_x_offset.shape == num_rays_shape + (2,)
@@ -648,6 +648,9 @@ class Cameras(TensorDataclass):
distortion_params[mask, :], distortion_params[mask, :],
).reshape(-1, 2) ).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 # Make sure after we have undistorted our images, the shapes are still correct
assert coord_stack.shape == (3,) + num_rays_shape + (2,) assert coord_stack.shape == (3,) + num_rays_shape + (2,)