问题描述
我有一个被扭曲"的原始图像.有人可以通过数学帮助我计算出原始图像中给定点在变形的位置上出现的位置吗?
I have an original image that has been "warped". Can someone help me with the math to calculate where a given point from the original image would show up in the warped one?
我有一个带有矩形的图像.我知道在平面图像中点A,B,C,D,E和F在哪里.
I have an image with a rectangle inside of it. I know where, in the flat image the points A, B, C, D, E and F are.
+------------------------------------------------+
| |
| A B |
| +-------------------+ |
| | | |
| | •F | |
| | | |
| | | |
| | | |
| | •E | |
| +-------------------+ |
| C D |
| |
+------------------------------------------------+
新图像(A')是由于相机的不正确设置而创建的,从而使图像变形.我现在有A',B',C'D',E',F'.
The new image (A') was create due to an imperfect setup of a camera, which has warped the image. I now have A',B',C'D',E',F'.
我不一定要取消扭曲"图像,我只想要新的坐标空间中的坐标(该点已结束).假设我知道A,B,C,D,E,F,A',B',C',D'和E'的位置(在它们各自的图像中),那么足够的信息足以简单地计算出新的E'的位置点应该在图像中?
I don't necessarily want to "unwarp" the image, I just want the coordinates in the new coordinate space, where the point has ended up. Given that I know where A, B, C, D, E, F, A', B', C', D' and E' (in their respective image), is that enough information to simply calculate where the new E' point should be in the image?
我认为这是3D矩阵变换,但是数学超出了我的范围,我正在尝试找出可以解决(E)新坐标的方程式.从技术上讲,我猜这是一个2D对象,它通过3D空间投影到2D表面上.
I feel that this is a 3D matrix transformation, but the math is beyond me and I'm trying to figure out the equations that would just solve for (E')s new coordinates. I guess technically this is a 2D object that was projected through 3D space onto a 2D surface.
+------------------------------------------------+
| |
| A' |
| +--------- B' |
| | -----------+ |
| | | |
| | •F' | |
| | | |
| | | |
| | | |
| | •E' | |
| | -------+ |
| +------------ D' |
| C' |
| |
+------------------------------------------------+
如果我需要添加另一个点(G和G'),以便求解E',则可以添加它.
If I need to add another point (G and G'), in order to solve for E', I could add it.
我能够理解的是,这将解决一系列联立方程,但是我不确定要解决E'(x,y)需要多少个已知".
What I've been able to understand is that this would be solving a series of simultaneous equations, but I'm not sure how many "knowns" are needed to solve for E'(x,y).
我正在iOS(目标C)中执行此操作,但是我并不关心实际的编码,实际上我只是在尝试找到解决方案矩阵(如果这是正确的术语).
I'm doing this in iOS (Objective C), but I'm not so concerned with the actual coding, I'm really just trying to find the solution matrix (if that is the right term).
推荐答案
此变换(具有透视效果的2D到2D)是所谓的单应性,可以用8个系数(a
到h
):
This transformation (2D to 2D with a perspective effect) is a so-called homography, which can be described with 8 coefficients (a
to h
):
X = (a.x + b.y + c) / (g.x + h.y + 1)
Y = (d.x + e.y + f) / (g.x + h.y + 1)
您可以轻松地将这些方程线性化为:
You can easily linearize these equations as:
a.x + b.y + c - g.x.X - h.y.X = X
d.x + e.y + f - g.x.Y - h.y.Y = Y
您可以通过取四个点(四个角)来求解它们,这将在八个未知数中为您提供八个方程,然后您可以在其中变换任何新点.
You solve them by taking four points (the four corners), which give you eight equations in eight unknowns, and from there you can transform any new point.
由于单应性的倒数也是单应性,因此可以以两种方式应用此分辨率(直变或扭曲).确保您要查找的未知坐标在上述开发中显示为(X, Y)
(而不是(x, y)
).
As the inverse of an homography is also an homography, you can apply this resolution in two ways (upright to distorted or conversely). Make sure that the unknown coordinates that you are looking for appear as (X, Y)
(rather than (x, y)
) in the above developments.
这篇关于在变形的2D图像中定位一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!