jasonyzhang / RayDiffusion

Code for "Cameras as Rays"
MIT License
525 stars 24 forks source link

Question about values of focal length and principal point #11

Closed hunminkim98 closed 8 months ago

hunminkim98 commented 8 months ago

Hi, Jason I appreciate your awesome work! It must be a useful tool for many people.

I have a question about the value of K. When I print both the focal length and principal point, the result is like this :

""" focal_lengths: tensor([[0.3149, 0.3209], [0.3000, 0.2843], [0.3330, 0.3335], [0.2724, 0.2953], [0.3503, 0.3805]], device='cuda:0') principal_points: tensor([[-0.0115, 0.0862], [-0.1158, -0.0176], [-0.0770, 0.0888], [-0.1703, -0.0015], [-0.0304, 0.0290]], device='cuda:0') focal_lengths: tensor([[0.3209, 0.3226], [0.3127, 0.3165], [0.3380, 0.3470], [0.2793, 0.2959], [0.3506, 0.3652]], device='cuda:0') principal_points: tensor([[-0.0400, 0.0101], [-0.0362, -0.0510], [-0.1211, -0.0234], [-0.1589, -0.1613], [ 0.0055, 0.0612]], device='cuda:0') """

It does not have the usual format of value. ( in both demo data and custom data ) I'm not sure, but it is due to normalization or other formats of representation in their coordination. Anyway, how can I get K in the usual format? Usual format example : [1850.0, 0.0, 1920.0] [0.0, 1850.0, 1080.0] [0.0, 0.0, 1.0]

Thanks again for the great work and I look forward to your response!

jasonyzhang commented 8 months ago

Our intrinsics are defined in normalized device coordinates. The intrinsics that you want are defined in screen coordinates. You can refer to here to see the conventions that Pytorch3D uses.

I think (but not 100% sure) that you can do the following to convert between pytorch3d ndc to screen coordinates:

L = min(height, width)
f_x = L * f_ndc_x / 2
f_y = L * f_ndc_y / 2
p_x = -(L * p_ndc_x - width) / 2
p_y = -(L * p_ndc_y - height) / 2

Note that the intrinsics output by our method are not necessarily that accurate. If I remember correctly, the focal lengths are we output are actually inverted (so you should use 1 / f).