寻找世界空间坐标像素的OpenCV
我需要找到使用OpenCV的像素的世界坐标。所以,当我把像素(0,0)在我的形象(这是左上角),我想知道什么3D世界空间坐标该像素对应于我像面。我知道,一个单一象素对应的线的世界空间中的3D点,但我希望特定一个位于该图像平面本身
I need to find the world coordinate of a pixel using OpenCV. So when I take pixel (0,0) in my image (that's the upper-left corner), I want to know to what 3D world space coordinate this pixel corresponds to on my image plane. I know that a single pixel corresponds to a line of 3D points in world space, but I want specific the one that lies on the image plane itself.
这是OpenCV的针孔模型,我有了第一个(内在)和第二(extrinsics)矩阵的计算公式。我知道我有u和v,但我不知道怎么从这个U和V的正确X搞定,Y和Z坐标。
This is the formula of the OpenCV Pinhole model of which I have the first (intrinsics) and second (extrinsics) matrices. I know that I have u and v, but I don't know how to get from this u and v to the correct X, Y and Z coordinate.
我已经尝试过:
- 我以为只是集合S为1,并从[UV 1] ^ T加1,像这样一个齐次坐标:UV 1 1] ^ T。然后,我乘以extrinsics的内在,并通过添加以下行把它做成一个4x4矩阵:[0 0 0 1]。这是反转而用[UV 1 1] ^ T相乘得到我的X,Y和Z.但是,当我检查,如果这样计算的四个像素趴在同一平面上(像平面),这是错误的。
所以,任何想法?
IIUC要的交点余与光线的像面处的背项目从摄像机中心的给定象素P
IIUC you want the intersection I with the image plane of the ray that back-projects a given pixel P from the camera center.
让我们先定义坐标系。通常的OpenCV的约定如下:
Let's define the coordinate systems first. The usual OpenCV convention is as follows:
- 图像坐标:原点在左上角,U轴在朝好的方向发展(增加列)和V轴下降 。
- 摄像机坐标:原点在摄像机中心C,Z轴会往现场,X轴在朝好的方向和Y轴将向下 。
然后,在摄像头的帧图像平面为z =的 FX 的,其中FX是焦距以像素为单位,并且像素(U,V)的摄像头坐标(u - 的 CX 的,V - CY 的 FX 的)。
Then the image plane in camera frame is z=fx, where fx is the focal length measured in pixels, and a pixel (u, v) has camera coordinates (u - cx, v - cy, fx).
由(固有)摄像头矩阵K,你会得到相同的一点格律摄像机坐标的倒数乘以他们。
Multiply them by the inverse of the (intrinsic) camera matrix K you'll get the same point in metrical camera coordinates.
最后,乘上世界对相机逆坐标变换[R | T],你会得到相同的点世界坐标。
Finally, multiply that by the inverse of the world-to-camera coordinate transform [R | t] and you'll get the same point in world coordinates.