Add PyTorch3D->OpenCV camera parameter conversion.

Summary: This diff implements the inverse of D28992470 (8006842f2a): a function to extract OpenCV convention camera parameters from a PyTorch3D `PerspectiveCameras` object. This is the first part of the new PyTorch3d<>OpenCV<>Pulsar conversion functions.

Reviewed By: patricklabatut

Differential Revision: D29278411

fbshipit-source-id: 68d4555b508dbe8685d8239443f839d194cc2484
This commit is contained in:
Christoph Lassner
2021-06-23 14:37:10 -07:00
committed by Facebook GitHub Bot
parent e4039aa570
commit da9974b416
3 changed files with 65 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ from pytorch3d.ops import eyes
from pytorch3d.transforms import so3_exponential_map, so3_log_map
from pytorch3d.utils import (
cameras_from_opencv_projection,
opencv_from_cameras_projection,
)
DATA_DIR = get_tests_dir() / "data"
@@ -151,3 +152,11 @@ class TestCameraConversions(TestCaseMixin, unittest.TestCase):
self.assertClose(
pts_proj_opencv_in_pytorch3d_screen, pts_proj_pytorch3d, atol=1e-5
)
# Check the inverse.
rvec_i, tvec_i, camera_matrix_i = opencv_from_cameras_projection(
cameras_opencv_to_pytorch3d, image_size
)
self.assertClose(rvec, rvec_i)
self.assertClose(tvec, tvec_i)
self.assertClose(camera_matrix, camera_matrix_i)