如何将世界坐标转换为相机坐标? [英] How does one convert world coordinates to camera coordinates?

查看:37
本文介绍了如何将世界坐标转换为相机坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入 3D 矢量,以及相机的俯仰和偏航.任何人都可以描述或提供资源链接以帮助我理解和实施所需的转换和矩阵映射吗?

解决方案

世界到相机变换矩阵是相机到世界矩阵的逆矩阵.相机到世界矩阵是相机位置的平移和相机方向的旋转的组合.因此,如果 M 是对应于相机方向的 3x3 旋转矩阵,t 是相机的位置,那么 4x4 相机到世界矩阵是:

<前>M00 M01 M02 txM10 M11 M12 tyM20 M21 M22 tz0 0 0 1

请注意,我假设向量是在右侧相乘以执行转换的列向量.如果您使用相反的约定,请确保转置矩阵.

要查找 M,您可以使用 上列出的公式之一维基百科,取决于您对滚转、俯仰和偏航的特定约定.请记住,这些公式使用的约定是向量是在左侧相乘的行向量.

不是计算相机到世界矩阵并将其求逆,一种更有效(且数值稳定)的替代方法是直接计算世界到相机矩阵.为此,只需反转相机的位置(通过否定所有 3 个坐标)及其方向(通过否定滚动、俯仰和偏航角,并将它们调整到适当的范围内),然后使用相同的方法计算矩阵算法.

I have an input 3D vector, along with the pitch and yaw of the camera. Can anyone describe or provide a link to a resource that will help me understand and implement the required transformation and matrix mapping?

解决方案

The world-to-camera transformation matrix is the inverse of the camera-to-world matrix. The camera-to-world matrix is the combination of a translation to the camera's position and a rotation to the camera's orientation. Thus, if M is the 3x3 rotation matrix corresponding to the camera's orientation and t is the camera's position, then the 4x4 camera-to-world matrix is:

M00 M01 M02 tx
M10 M11 M12 ty
M20 M21 M22 tz
0   0  0   1

Note that I've assumed that vectors are column vectors which are multiplied on the right to perform transformations. If you use the opposite convention, make sure to transpose the matrix.

To find M, you can use one of the formulas listed on Wikipedia, depending on your particular convention for roll, pitch, and yaw. Keep in mind that those formulas use the convention that vectors are row vectors which are multiplied on the left.

Instead of computing the camera-to-world matrix and inverting it, a more efficient (and numerically stable) alternative is to calculate the world-to-camera matrix directly. To do so, just invert the camera's position (by negating all 3 coordinates) and its orientation (by negating the roll, pitch, and yaw angles, and adjusting them to be in their proper ranges), and then compute the matrix using the same algorithm.

这篇关于如何将世界坐标转换为相机坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆