Skip to content

Convert camera extrinsic openCV to R and T matrix of SfMPerspectiveCameras #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hiro050696 opened this issue Jul 24, 2020 · 7 comments
Closed
Assignees
Labels
how to How to use PyTorch3D in my project

Comments

@hiro050696
Copy link

hiro050696 commented Jul 24, 2020

camera_pose  = np.array([[ 0.10624042,  0.99397693,  0.0268858,   0.2087519 ],
                            [-0.68876547,  0.05406284,  0.72296565,  0.61393758],
                            [ 0.71715765, -0.09532618,  0.69036065,  3.16445006],
                            [0.0        ,           0.0,        0.0,        1.0]])


def getNewCameraPose(camera_pose=camera_pose):
    rot_X       = np.array([[ 1.0, 0.0, 0.0, 0],
                            [ 0.0, -1.0, 0.0, 0],
                            [ 0.0, 0.0, -1.0, 0],
                            [0, 0, 0, 1]])
    rot_X_1     = np.array([[ 1.0, 0.0, 0.0, 0],
                            [ 0.0, 0.0, 1.0, 0],
                            [ 0.0, -1.0, 0.0, 0],
                            [0, 0, 0, 1]])
    A = np.dot(rot_X,camera_pose)
    A = np.dot(A,rot_X_1)
    camera_pose = np.linalg.inv(A)
    return camera_pose

camera_pose = getNewCameraPose(camera_pose=camera_pose)
R 			= torch.Tensor([camera_pose[:3,:3]])
T 			= torch.Tensor([camera_pose[:3,3]])

After using OpenCV cabliration, i got a 4x4 extrinsic matrix. I want to convert it to 2 matrix R and T form OpenCV coordinate to Pytorch3D coordinate, those matrix are used in SfMPerspectiveCameras projection function.
I tried a lot of approach but it didnt work correctly, maybe the problem is related to right-hand and left-hand coordinate system.

How can I do it?

@nikhilaravi nikhilaravi added the how to How to use PyTorch3D in my project label Jul 24, 2020
@nikhilaravi nikhilaravi self-assigned this Jul 27, 2020
@nikhilaravi
Copy link
Contributor

So to clarify you used the R & T (from the code example above) with SfMPerspectiveCameras and did got get the correct rendering/transformation result?

There are two things you should check:

@gkioxari
Copy link
Contributor

Here is another illustration of the coordinate systems if it helps

cameras

@gkioxari
Copy link
Contributor

We have provided a more comprehensive description of our cameras along with coordinate systems. You can read more in our notes here:

https://github.com/facebookresearch/pytorch3d/blob/master/docs/notes/cameras.md

and also in the codebase. Let us know if you need any more info.

@nikhilaravi
Copy link
Contributor

@hiro050696 we will close this issue. If you have further questions feel free to reopen it.

@BostonLobster
Copy link

@hiro050696 Have you solved this problem? I'm also trying to convert extrinsics from ScanNet (which is in OpenCV coordinate system), but feeding converted [R, T] into SfMPerspective got empty rendering results.

@jbohnslav
Copy link

I'm also working on this problem. Has anyone figured it out?

Looking at the opencv documentation, I think the reason for the issue is the coordinate systems. OpenCV uses a X-right, Y-down, Z-out (positive) coordinate system for pinhole camera model
image

As Nikhila and Georgia showed in the really nice docs, Pytorch3D uses a X-left, Y-up, Z-out coordinate system.

@pengsongyou
Copy link

Hi,

For those who are still looking for the solution, here is my solution: #522 (comment).
Hope it helps.

Best,
Songyou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
how to How to use PyTorch3D in my project
Projects
None yet
Development

No branches or pull requests

6 participants