在 OpenCV 中查找像素的世界空间坐标 [英] Find world space coordinate for pixel in OpenCV

查看:61
本文介绍了在 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 针孔模型的公式,其中我有第一个(内在的)和第二个(外在的)矩阵.我知道我有 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,然后通过添加 1 来从 [u v 1]^T 生成齐次坐标,如下所示:[u v 1 1]^T.然后我将内在函数与外在函数相乘,并通过添加以下行使其成为 4x4 矩阵:[0 0 0 1].然后将其反转并乘以 [uv 1 1]^T 以获得我的 X、Y 和 Z.但是当我检查这样计算的四个像素是否位于同一平面(图像平面)上时,这是错误的.

那么,有什么想法吗?

推荐答案

IIUC 您希望 I 与从相机中心反向投影给定像素 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.

这篇关于在 OpenCV 中查找像素的世界空间坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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