如何将投影的 3D 矩形转换为 2D 轴对齐矩形

发布于 2024-10-05 23:53:56 字数 153 浏览 1 评论 0原文

我有一个 3D 矩形的图像(由于投影失真,它不是图像中的矩形)。我知道这个矩形所有角的所有世界坐标和图像坐标。

我需要的是确定该矩形内图像中的点的世界坐标。为此,我需要计算一个变换,将该矩形取消投影为 2D 矩形。

我如何计算该变换?

提前致谢

I have an image of a 3D rectangle (which due to the projection distortion is not a rectangle in the image). I know the all world and image coordinates of all corners of this rectangle.

What I need is to determine the world coordinate of a point in the image inside this rectangle. To do that I need to compute a transformation to unproject that rectangle to a 2D rectangle.

How can I compute that transform?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琴流音 2024-10-12 23:53:56

这是查找保留直线的四边形之间的映射的特殊情况。这些通常称为单应变换。在这里,其中一个四边形是矩形,因此这是一种流行的特殊情况。您可以通过谷歌搜索这些术语(“四元到四元”等)来查找解释和代码,但这里有一些适合您的网站。

透视变换估计

游戏论坛讨论

将四边形图像提取到矩形

投影变形 & ;映射

用于图像变形的投影映射作者:保罗·赫克伯特。

数学不是特别令人愉快,但也不是那么难。您还可以从上述链接之一找到一些代码。

This is a special case of finding mappings between quadrilaterals that preserve straight lines. These are generally called homographic transforms. Here, one of the quads is a rectangle, so this is a popular special case. You can google these terms ("quad to quad", etc) to find explanations and code, but here are some sites for you.

Perspective Transform Estimation

a gaming forum discussion

extracting a quadrilateral image to a rectangle

Projective Warping & Mapping

ProjectiveMappings for ImageWarping by Paul Heckbert.

The math isn't particularly pleasant, but it isn't that hard either. You can also find some code from one of the above links.

樱花坊 2024-10-12 23:53:56

如果我理解正确的话,那么在矩形的投影中有一个 2D 点,并且您知道矩形所有四个角的 3D(世界)和 2D(图像)坐标。目标是找到投影到给定点的(3D,世界)矩形内部唯一点的 3D 坐标。

(对矩形的 3D(世界)坐标和 2D(图像)坐标执行下面的步骤 1-3。)

  1. 将矩形的(任何)一个角确定为其“原点”,并将其命名为“A”,我们将其视为向量。
  2. 按顺序标记其他顶点 B、C、D,使 C 与 A 对角相对。
  3. 计算向量 v=AB 和 w=AD。这些为矩形中的点形成了很好的局部坐标。矩形中的点的形式为 A+rv+sw,其中 r、s 是 [0,1] 范围内的实数。这一事实在世界坐标图像坐标中都是正确的。在世界坐标中,v 和 w 是正交的,但在图像坐标中,它们不是正交的。没关系。
  4. 在图像坐标中,从矩形图像中的点 (x,y) 计算 r 和 s 的值。这可以通过向量方程 (x,y) = A+rv+sw 的线性代数来完成,其中只有 r 和 s 未知。它将归结为 2x2 矩阵方程,您通常可以使用克拉默规则在代码中求解。 (如果所需矩阵的行列式为零,则此步骤将中断。这对应于矩形边缘朝上的情况。在这种情况下,解决方案不是唯一的。如果可能,请特别例外。
  5. ) r 和 s 的值从 4 开始,使用向量 A、v、w 计算 A+rv+sw,作为世界坐标。那是矩形上的世界点。

If I understand you correctly, you have a 2D point in the projection of the rectangle, and you know the 3D (world) and 2D (image) coordinates of all four corners of the rectangle. The goal is to find the 3D coordinates of the unique point on the interior of the (3D, world) rectangle which projects to the given point.

(Do steps 1-3 below for both the 3D (world) coordinates, and the 2D (image) coordinates of the rectangle.)

  1. Identify (any) one corner of the rectangle as its "origin", and call it "A", which we will treat as a vector.
  2. Label the other vertices B, C, D, in order, so that C is diagonally opposite A.
  3. Calculate the vectors v=AB and w=AD. These form nice local coordinates for points in the rectangle. Points in the rectangle will be of the form A+rv+sw, where r, s, are real numbers in the range [0,1]. This fact is true in world coordinates and in image coordinates. In world coordinates, v and w are orthogonal, but in image coordinates, they are not. That's ok.
  4. Working in image coordinates, from the point (x,y) in the image of your rectangle, calculate the values of r and s. This can be done by linear algebra on the vector equations (x,y) = A+rv+sw, where only r and s are unknown. It will boil down to a 2x2 matrix equation, which you can solve generally in code using Cramer's rule. (This step will break if the determinant of the required matrix is zero. This corresponds to the case where the rectangle is seen edge-on. The solution isn't unique in that case. If that's possible, make special exception.)
  5. Using the values of r and s from 4, compute A+rv+sw using the vectors A, v, w, for world coordinates. That's the world point on the rectangle.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文