diff --git a/pytorch3d/renderer/cameras.py b/pytorch3d/renderer/cameras.py index b9338723..6444cbae 100644 --- a/pytorch3d/renderer/cameras.py +++ b/pytorch3d/renderer/cameras.py @@ -505,8 +505,8 @@ class SfMPerspectiveCameras(TensorProperties): py = principal_point[:,1] P = [ - [fx, 0, 0, px], - [0, fy, 0, py], + [fx, 0, px, 0], + [0, fy, py, 0], [0, 0, 0, 1], [0, 0, 1, 0], ] @@ -800,8 +800,8 @@ def _get_sfm_calibration_matrix( ] else: K = [ - [fx, 0, 0, px], - [0, fy, 0, py], + [fx, 0, px, 0], + [0, fy, py, 0], [0, 0, 0, 1], [0, 0, 1, 0], ] @@ -827,12 +827,14 @@ def _get_sfm_calibration_matrix( K = fx.new_zeros(N, 4, 4) K[:, 0, 0] = fx K[:, 1, 1] = fy - K[:, 0, 3] = px - K[:, 1, 3] = py if orthographic: + K[:, 0, 3] = px + K[:, 1, 3] = py K[:, 2, 2] = 1.0 K[:, 3, 3] = 1.0 else: + K[:, 0, 2] = px + K[:, 1, 2] = py K[:, 3, 2] = 1.0 K[:, 2, 3] = 1.0 diff --git a/tests/test_cameras.py b/tests/test_cameras.py index 6e22e702..da35b4e7 100644 --- a/tests/test_cameras.py +++ b/tests/test_cameras.py @@ -81,8 +81,8 @@ def sfm_perspective_project_naive(points, fx=1.0, fy=1.0, p0x=0.0, p0y=0.0): (N, V, 3) tensor of projected points. """ z = points[:, :, 2] - x = (points[:, :, 0] * fx + p0x) / z - y = (points[:, :, 1] * fy + p0y) / z + x = (points[:, :, 0] * fx) / z + p0x + y = (points[:, :, 1] * fy) / z + p0y points = torch.stack((x, y, 1.0 / z), dim=2) return points