如何找到投影矩形的 3D 坐标?
我有以下问题,主要是算法问题。
- 设 ABCD 是位于空间某处的已知尺寸 d1、d2 的矩形。
- 矩形 ABCD 投影在平面 P 上(一般情况下形成梯形 KLMN)。 我知道投影矩阵H。
- 我还可以找到梯形边缘点K、L、M、N的二维坐标。
问题如下:
- 给定投影矩阵 H、梯形上边缘的坐标以及我们的对象是具有指定几何形状(尺寸 d1、d2)的矩形的知识,我们可以计算点 A 的 3D 坐标吗?乙、丙、丁?
我正在用单个相机抓取简单矩形的图像,并且我想在空间上重建矩形。 我可以抓取多个图像并使用三角测量,但这不是我们想要的。
仅投影矩阵是不够的,因为光线被投影到同一点。 该物体具有已知尺寸的事实使我相信该问题是可以解决的并且存在有限的解决方案。
如果我弄清楚如何进行这种重建,我就知道如何对其进行编程。 所以我要求一个算法/数学答案。
任何想法都欢迎 谢谢
I have the following problem which is mainly algorithmic.
- Let ABCD be a rectangle with known dimensions d1, d2 lying somewhere in space.
- The rectangle ABCD is projected on a plane P (forming in the general case a trapezium KLMN). I know the projection matrix H.
- I can also find the 2D coordinates of the trapezium edge points K,L,M,N.
The Question is the following :
- Given the Projection Matrix H, The coordinates of the edges on the trapezium and the knowledge that our object is a rectangle with specified geometry (dimensions d1, d2), could we calculate the 3D coordinates of the points A, B, C, D ?
I am grabbing images of simple rectangles with a single camera and i want to reconstruct the rectangles on space. I could grab more than one image and use triangulation but this is not desired.
The projection Matrix alone isn't enough since a ray is projected to the same point. The fact that the object has known dimensions, makes me believe that the problem is solvable and there are finite solutions.
If I figure out how this reconstruction can be made I know how to program it. So I am asking for an algorithmic/math answer.
Any ideas are welcome
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我将在这里给出一个相当简短的答案,但我想您会明白我的大致意思。 我假设你有一个 3x4 投影矩阵 (P),所以你应该能够通过找到 P 的正确零向量来获得相机中心:将其称为 C。
一旦你有了 C,你将能够计算光线与向量 CK、CL、CM 和 CN 方向相同(即 C 和 K、L、M 或 N 的叉积,例如 CxK)
现在您所要做的就是计算 3 个点 (u1,u2,u3)满足以下 6 个约束(任意假设 KL 和 KN 相邻,并且 ||KL|| >= ||KN|| 如果 d1 >= d2):
其中,AB = 向量 A 和 B 的点积
||一个|| = A 的欧几里得范数
AxB = A 和 B 的叉积
I'm going to give a fairly brief answer here, but I think you'll get my general drift. I'm assuming you have a 3x4 projection matrix (P), so you should be able to get the camera centre by finding the right null vector of P: call it C.
Once you have C, you'll be able to compute rays with the same direction as vectors CK,CL,CM and CN (i.e. the cross product of C and K,L,M or N, e.g. CxK)
Now all you have to do is compute 3 points (u1,u2,u3) which satisfies the following 6 constraints (arbitrarily assuming KL and KN are adjacent and ||KL|| >= ||KN|| if d1 >= d2):
where, A.B = dot product of vectors A and B
||A|| = euclidean norm of A
AxB = cross product of A and B
我认为这个问题将产生一组可能的解决方案,至少在二维方面是这样。 对于 2D 情况:
在上图中,垂直线段和水平线段将投影到视图平面 (VP) 上的同一条线。 如果你按比例绘制它,你会看到有两条来自眼睛的光线穿过未投影线的每个端点。 这条线可以处于多种位置和旋转 - 想象一下将一根棍子放入圆锥体中,它可以卡在任意数量的位置。
因此,在 2D 空间中,在明确定义的集合中存在无限多个解。
这适用于 3D 吗?
该算法将遵循以下原则:
编辑:如果你知道到物体的距离,它就会变得微不足道。
编辑V2:
好的,让Rn是世界空间中的四条射线,即通过逆矩阵进行变换,以m.Rn表示,其中|Rn| 是一。 因此,矩形的四个点是:
其中 P1..P4 是围绕矩形圆周的点。 由此,使用一些向量数学,我们可以推导出四个方程:
其中 d1 和 d2 是矩形边的长度,a、b、c 和 d 是未知数。
现在,上述情况可能没有解决方案,在这种情况下您需要将 d1 与 d2 交换。 您可以将每一行展开为:
(a.R1x - b.R2x)2 + (a.R1y - b.R2y)2 + (a.R1z - b. R2z)2 = d12
其中 R1? 和R2? 是射线 1 和 2 的 x/y/z 分量。请注意,您在上面求解的是 a 和 b,而不是 x、y、z。
I think this problem will generate a set of possible solutions, at least in 2D it does. For the 2D case:
In the above diagram, the vertical segment and the horizontal segment would project to the same line on the view plane (VP). If you drew this out to scale you'd see that there are two rays from the eye passing through each end point of the unprojected line. This line can be in many positions and rotations - imagine dropping a stick into a cone, it can get stuck in any number of positions.
So, in 2D space there are an infinite number of solutions within a well defined set.
Does this apply to 3D?
The algorithm would be along the lines of:
EDIT: If you knew the distance to the object it would become trivial.
EDIT V2:
OK, let Rn be the four rays in world space, i.e. transformed via the inverse matrix, expressed in terms of m.Rn, where |Rn| is one. The four points of the rectange are therefore:
where P1..P4 are the points around the circumference of the rectangle. From this, using a bit of vector maths, we can derive four equations:
where d1 and d2 are the lengths of the sides of the rectangle and a, b, c and d are the unknowns.
Now, there may be no solution to the above in which case you'd need to swap d1 with d2. You can expand each line to:
(a.R1x - b.R2x)2 + (a.R1y - b.R2y)2 + (a.R1z - b.R2z)2 = d12
where R1? and R2? are the x/y/z components of rays 1 and 2. Note that you're solving for a and b in the above, not x,y,z.
m_oLogin 是对的。 如果我理解你的目标,相机拍摄的图像就是平面 P,对吧? 如果是这样,您正在测量 2D 图像的 K、L、M、N。 你需要投影矩阵的逆来重建 A、B、C 和 D。
我以前从未这样做过,但我突然想到,你可能会遇到与 GPS 仅修复 3 个卫星时遇到的相同问题 - 有有两种可能的解决方案,一种在 P 的“后面”,一种在 P 的“前面”,对吧?
m_oLogin is right. If I understand your goal, the image the camera snaps is the plane P, right? If so, you're measuring K,L,M,N off the 2D image. You need the inverse of the projection matrix to reconstruct A,B,C, and D.
Now I've never done this before, but it ocurrs to me that you might run into the same problem GPS does with only 3 satellite fixes - there are two possible solutions, one 'behind' P and one 'in front' of it, right?
投影矩阵封装了透视和比例,因此逆矩阵将为您提供所需的解决方案。 我认为您假设它仅封装了视角,并且您需要其他东西来选择正确的比例。
The projection matrix encapsulates both the perspective and scale, so the inverse will give you the solution you are after. I think you are assuming that it only encapsulates the perspective, and you need something else to choose the correct scale.
您需要计算投影矩阵的逆矩阵。 (你的矩阵不能是奇异的)
You need to calculate the inverse of your projection matrix. (your matrix cannot be singular)