fraunhoferhhi / neural-deferred-shading

Multi-View Mesh Reconstruction with Neural Deferred Shading (CVPR 2022)
Other
254 stars 21 forks source link

Camera convention #11

Closed YaroslavShchekaturov closed 1 year ago

YaroslavShchekaturov commented 1 year ago

Hi there!

Which camera convention do you use? Is Rt a c2w or w2c matrix here?

def to_gl_camera(camera, resolution, n=1000, f=5000):

    projection_matrix = Renderer.projection(fx=camera.K[0,0],
                                            fy=camera.K[1,1],
                                            cx=camera.K[0,2],
                                            cy=camera.K[1,2],
                                            n=n,
                                            f=f,
                                            width=resolution[1],
                                            height=resolution[0],
                                            device=camera.device)

    Rt = torch.eye(4, device=camera.device)
    Rt[:3, :3] = camera.R
    Rt[:3, 3] = camera.t

    gl_transform = torch.tensor([[1., 0,  0,  0],
                                [0,  1., 0,  0],
                                [0,  0, -1., 0],
                                [0,  0,  0,  1.]], device=camera.device)

    Rt = gl_transform @ Rt
    return projection_matrix @ Rt
mworchel commented 1 year ago

Hi!

Rt is w2c (there is a formula in the README in Section Reconstructing Custom Scenes).

So for the given function, Rt transforms a world point to OpenCV camera space, and the matrix gl_transform transforms the point from OpenCV camera space to OpenGL camera space. The projection_matrix uses OpenGL conventions for the clip space transformation.

YaroslavShchekaturov commented 1 year ago

Dear @mworchel Thank you very much for your response!