OpenGL中的3D渲染:模型/视图/投影与平移/旋转/相机矩阵

时间:2021-12-29 06:05:39

I want to add to a captured frame from a camera a mesh model (Let's say a cube)

我想从相机中添加一个捕获的帧,一个网格模型(让我们说一个立方体)

I also know all the information about where to put the cube:

我也知道有关放置多维数据集的位置的所有信息:

  1. Translation matrix - relative to the camera
  2. 翻译矩阵 - 相对于相机
  3. Rotation matrix - relative to the camera
  4. 旋转矩阵 - 相对于相机
  5. camera calibration matrix - focal length, principal point, etc. (intrinsic parameters)
  6. 相机校准矩阵 - 焦距,主点等(内在参数)

How can I convert this information to model/view/projection matrices?

如何将此信息转换为模型/视图/投影矩阵?

What should be the values to set to these matrices?

设置为这些矩阵的值应该是多少?

For example, let's say that I want to display the point [x, y, z, 1] on the screen, then that should be something like: [u, v, 1] = K * [R | T] * [x, y, z, 1], while:

例如,假设我想在屏幕上显示点[x,y,z,1],那么应该是这样的:[u,v,1] = K * [R | T] * [x,y,z,1],而:

u, v are the coordinates in the screen (or camera capture) and:

u,v是屏幕(或摄像头捕获)中的坐标,并且:

K, R and T are intrinsic camera parameters, rotation and translation, respectively.

K,R和T分别是固有的相机参数,旋转和平移。

How to convert K, R, T to model/view/projection matrices?

如何将K,R,T转换为模型/视图/投影矩阵?

2 个解决方案

#1


2  

[R | T] would be your model-view matrix and K would be your projection matrix.

[R | T]将是您的模型视图矩阵,K将是您的投影矩阵。

Model-view matrix is usually one matrix. The separation is only conceptual: Model translates from model coordinates to world coordinates and View from world coordinates to camera (not-yet-projected) coordinates. It makes sense in applications where the camera and the objects move independently from each other. In your case, on the other hand, camera can be considered fixed and everything else described relative to the camera. So you have to deal only with two matrices: model-view and projection.

模型 - 视图矩阵通常是一个矩阵。分离只是概念性的:模型从模型坐标转换为世界坐标,从世界坐标转换到相机(尚未投影)坐标。在相机和物体彼此独立移动的应用中,它是有意义的。另一方面,在您的情况下,可以认为相机是固定的,并且相对于相机描述了其他所有内容。因此,您只需要处理两个矩阵:模型视图和投影。

#2


2  

Assuming that your camera intrinsic matrix comes from OpenCV (http://docs.opencv.org/2.4/doc/tutorials/calib3d/camera_calibration/camera_calibration.html), how to initialize your OpenGL projection matrix is described there: https://blog.noctua-software.com/opencv-opengl-projection-matrix.html

假设您的相机内部矩阵来自OpenCV(http://docs.opencv.org/2.4/doc/tutorials/calib3d/camera_calibration/camera_calibration.html),那么如何初始化您的OpenGL投影矩阵:https:// blog.noctua-software.com/opencv-opengl-projection-matrix.html

OpenGL中的3D渲染:模型/视图/投影与平移/旋转/相机矩阵
cx, cy, width and height are in pixels

cx,cy,width和height以像素为单位

As for your OpenGL model-view matrix, it's really simple:

至于你的OpenGL模型 - 视图矩阵,它非常简单:

OpenGL中的3D渲染:模型/视图/投影与平移/旋转/相机矩阵
So in the end your model-view-projection matrix is:

所以最后你的模型 - 视图 - 投影矩阵是:

OpenGL中的3D渲染:模型/视图/投影与平移/旋转/相机矩阵

#1


2  

[R | T] would be your model-view matrix and K would be your projection matrix.

[R | T]将是您的模型视图矩阵,K将是您的投影矩阵。

Model-view matrix is usually one matrix. The separation is only conceptual: Model translates from model coordinates to world coordinates and View from world coordinates to camera (not-yet-projected) coordinates. It makes sense in applications where the camera and the objects move independently from each other. In your case, on the other hand, camera can be considered fixed and everything else described relative to the camera. So you have to deal only with two matrices: model-view and projection.

模型 - 视图矩阵通常是一个矩阵。分离只是概念性的:模型从模型坐标转换为世界坐标,从世界坐标转换到相机(尚未投影)坐标。在相机和物体彼此独立移动的应用中,它是有意义的。另一方面,在您的情况下,可以认为相机是固定的,并且相对于相机描述了其他所有内容。因此,您只需要处理两个矩阵:模型视图和投影。

#2


2  

Assuming that your camera intrinsic matrix comes from OpenCV (http://docs.opencv.org/2.4/doc/tutorials/calib3d/camera_calibration/camera_calibration.html), how to initialize your OpenGL projection matrix is described there: https://blog.noctua-software.com/opencv-opengl-projection-matrix.html

假设您的相机内部矩阵来自OpenCV(http://docs.opencv.org/2.4/doc/tutorials/calib3d/camera_calibration/camera_calibration.html),那么如何初始化您的OpenGL投影矩阵:https:// blog.noctua-software.com/opencv-opengl-projection-matrix.html

OpenGL中的3D渲染:模型/视图/投影与平移/旋转/相机矩阵
cx, cy, width and height are in pixels

cx,cy,width和height以像素为单位

As for your OpenGL model-view matrix, it's really simple:

至于你的OpenGL模型 - 视图矩阵,它非常简单:

OpenGL中的3D渲染:模型/视图/投影与平移/旋转/相机矩阵
So in the end your model-view-projection matrix is:

所以最后你的模型 - 视图 - 投影矩阵是:

OpenGL中的3D渲染:模型/视图/投影与平移/旋转/相机矩阵