OpenCV 和 PyTorch3D 相机投影
OpenCV Pinhole Camera: https://docs.opencv.org/3.4/d9/d0c/group__calib3d.html
Pytorch3D Camera: https://pytorch3d.org/docs/cameras
OpenCV 坐标系
OpenCV 的世界坐标系、相机坐标系都是右手系,+X 指向右侧,+Y 指向下方。
图像坐标系 +X 指向右侧,+Y 指向下方,原点在主点 (cx,cy)。
Pytorch3D 坐标系
Pytorch3D 的世界坐标系、相机坐标系、NDC 坐标系都是右手系,+X 指向左侧,+Y 指向上方。
屏幕坐标系 +X 指向右侧,+Y 指向下方,原点在左上方角落。
1 | import torch |
1 | def opencv_project(points, opencv_camera): |
1 | W, H = 256, 256 |
Input 3D points
torch.Size([2, 3])
OpenCV projection
torch.Size([2, 3])
tensor([[7.9467e+02, 4.6133e+02, 3.3333e-01],
[9.2800e+02, 2.2613e+03, 6.6667e-01]])
Pytorch3D opencv projection
torch.Size([2, 3])
tensor([[7.9467e+02, 4.6133e+02, 3.3333e-01],
[9.2800e+02, 2.2613e+03, 6.6667e-01]])
Pytorch3D PerspectiveCameras projection
torch.Size([2, 3])
tensor([[7.9467e+02, 4.6133e+02, 3.3333e-01],
[9.2800e+02, 2.2613e+03, 6.6667e-01]])
Compare OpenCV projection and Pytorch3D opencv projection: True
Compare OpenCV projection and PerspectiveCameras projection: True