pytorch3d icon indicating copy to clipboard operation
pytorch3d copied to clipboard

Is compute_projection_matrix in FoVPerspectiveCameras correct?

Open Xiaoming-Zhao opened this issue 1 year ago • 1 comments

❓ Questions on how to use PyTorch3D

Thanks a lot for the great work on this tool. I have a question about the compute_projection_matrix function of FoVPerspectiveCameras and hope you could give me a hand.

Essentially, I am wondering whether it is correct: https://github.com/facebookresearch/pytorch3d/blob/b95535c8b73299134bb2144a8b36edfffaf2e225/pytorch3d/renderer/cameras.py#L627-L638

To be specific, the projection matrix you define is: Screenshot 2023-01-19 at 18 33 44

where $n > 0, f > 0$ denotes the near and far planes and ${l, r, t, b }$ represents the x-max, x-min, y-max, and y-min boundaries.

According to this doc, the ideal situation is that $P_1$ will map

  • the point of $[l, 0, n]$ to NDC's left boundary, i.e., x-coordinate to be 1;
  • similarly, $[r, 0, n]$ to NDC's right boundary, i.e., x-coordinate to be -1;
  • $[0, t, n]$ to NDC's right boundary, i.e., y-coordinate to be 1;
  • $[0, b, n]$ to NDC's right boundary, i.e., y-coordinate to be -1.

However, I do not think $P_1$ can do it. Actually, I think $P_2$ should be implemented (pay attention to the negative sign of the third column):

Screenshot 2023-01-19 at 18 38 14

I encounter some problems recently so I investigate the definition of the projection matrix. May I know whether I miss something? Thanks in advance.

Xiaoming-Zhao avatar Jan 20 '23 00:01 Xiaoming-Zhao

As mentioned before the definition of K, min_x = -max_x. So, it doesn't matter +/- ...

Wind508 avatar Sep 12 '23 06:09 Wind508