透视投影,4点 [英] Perspective projection, 4 points

查看:113
本文介绍了透视投影,4点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施透视投影.例如,我有一个给定大小的正方形,并且已知角的坐标为(A1 .. A4).我有一个图像,其中该正方形显示在某些特定位置.我知道它的位置和所显示的正方形B1 .. B4的角的坐标.我想找到一个转换矩阵M 转换B->A.

I am trying to implement a perspective projection. For example, I have a square with a given size, and known corners' coordinates (A1 .. A4) . I have an image where this square is displayed at some specific position. I know its position and the coordinates of the corners of the displayed square B1 .. B4. I want to find a transformation matrix M that will translate B -> A.

我遵循方法数学插图,本章10,我设法很好地转换了3个角.但是我找不到矩阵可以正确转换4个角...我在第7页上找到了矩阵,但是不能很好地转换所有4个点.

I followed method Mathematical Illustrations, chapter 10, and I managed to transform 3 corners well. But I cannot find the matrix to transform correctly 4 corners... I find the matrix as on page 7, but it does not translate all 4 points well.

推荐答案

如您的参考资料所示,表示一般投影变换的标准方法是用w坐标来扩大(x,y)二维坐标(以获取同质坐标 [x,y,w]),并使用3x3矩阵对其进行转换.

As your reference indicates, the standard way to represent a general projective transformation is to augment your (x,y) 2-D coordinates with a w coordinate (to get homogeneous coordinates [x,y,w]), and use a 3x3 matrix to transform them.

从您的问题中并不清楚您当前正在如何尝试使用您的点,但是我怀疑如何使用额外的坐标有些混乱.从数学上讲,要记住的是,您可以将整个齐次矢量乘以任意的非零比例因子(因为最后除以第三个坐标将抵消比例因子).但是,有时很难弄清这在实际意义上是什么意思.

It is not clear from your question exactly how you are currently trying to use your points, but I suspect that there is some confusion with how to use the extra coordinate. Mathematically, the thing to remember is that you can multiply the entire homogeneous vector by an arbitrary nonzero scaling factor (because in the end dividing by the third coordinate will cancel out the scaling factor). However, it is sometimes hard to figure out what this means in a practical sense...

对于此问题,请按如下所示设置系统(我将同构坐标视为行向量,以匹配您的参考):

For this problem, set up the system as follows (I am treating homogeneous coordinates as row vectors here, to match your reference):

Find a 3x3 matrix T, such that:
  it maps each point b to corresponding point a:  a = b  T
  specifically:

     w' * [a_x a_y 1] = w * [b_x b_y 1] * [ T_xx T_xy T_xw ]
                                          [ T_yx T_yy T_yw ]
                                          [ T_wx T_wy T_ww ]

棘手的一点:您不能仅将ww'设置为1.这是因为投影变换T 不一定会使第三个坐标保持不变! (如果这样做,则可以完全跳过齐次位,并仅使用三对点进行仿射变换...).

The tricky bit: you can't just set w and w' to 1. This is because a projective transformation T doesn't necessarily leave the third coordinate unchanged! (If it did, you could skip the homogeneous bit altogether, and get an affine transform using only three point pairs...).

一种表达方式(很容易解决)是添加参数K = w' / w.然后,您可以将上述内容表达为线性系统,如下所示:

One way to express this (in a way that can be solved readily) is to add a parameter, K = w' / w. Then you can express the above as a linear system, as follows:

for each point b and corresponding point a,
  [a_x a_y 1] * K = [b_x b_y 1] * [ T_xx T_xy T_xw ]
                                  [ T_yx T_yy T_yw ]
                                  [ T_wx T_wy T_ww ]

请记住,所有ab值都是固定常数;您正在尝试求解T矩阵的九个元素.每个点对添加三个约束(来自上面的向量等式)和一个附加参数(该方程式的K),总共有4 * 3 = 12个约束和9 + 4 = 13个参数.所以,我们在这里缺少一个约束...

Remember, all the a and b values are fixed constants; you're trying to solve for the nine elements of your T matrix. Each point pair adds three constraints (from the vector equality above) and one additional parameter (the K for that equation), for a total of 4*3=12 constraints, and 9+4=13 parameters. So, we're missing one constraint here...

需要一个附加约束,因为矩阵T有效地具有任意缩放比例:它是在同构坐标之间映射(无论如何它们都划分了任意缩放比例),因此没有固有的方法来确定此缩放比例因素是.解决此问题的一种方法是任意设置T_ww = 1:

An additional constraint is needed because the matrix T effectively has an arbitrary scaling factor: it is mapping between homogeneous coordinates (which all divide out an arbitrary scaling factor anyway), so there is no inherent way to decide what this scaling factor is. One way to fix this factor is to arbitrarily set T_ww = 1:

for each point pair (a, b):
  [a_x a_y 1] * K = [b_x b_y 1] * [ T_xx T_xy T_xw ]
                                  [ T_yx T_yy T_yw ]
                                  [ T_wx T_wy  1   ]

这为您提供了一个完全确定的线性系统:

This gives you a fully-determined linear system:

  0  = b1_x*T_xx + b1_y*T_yx + 1*T_wx - a1_x*K1
  0  = b1_x*T_xy + b1_y*T_yy + 1*T_wy - a1_y*K1
-1*1 = b1_x*T_xw + b1_y*T_yw          -    1*K1

  0  = b2_x*T_xx + b2_y*T_yx + 1*T_wx - a2_x*K2
  0  = b2_x*T_xy + b2_y*T_yy + 1*T_wy - a2_y*K2
-1*1 = b2_x*T_xw + b2_y*T_yw          -    1*K2

  0  = b3_x*T_xx + b3_y*T_yx + 1*T_wx - a3_x*K3
  0  = b3_x*T_xy + b3_y*T_yy + 1*T_wy - a3_y*K3
-1*1 = b3_x*T_xw + b3_y*T_yw          -    1*K3

  0  = b4_x*T_xx + b4_y*T_yx + 1*T_wx - a4_x*K4
  0  = b4_x*T_xy + b4_y*T_yy + 1*T_wy - a4_y*K4
-1*1 = b4_x*T_xw + b4_y*T_yw          -    1*K4

您现在有了12个变量(矩阵元素T_**和其他缩放参数K*)中的12个线性方程.使用线性代数库求解系统并获得结果(假设您不想编写自己的求解器...).

You now have 12 linear equations in 12 variables (matrix elements T_** and additional scaling parameters K*). Use a linear algebra library to solve the system and get your results (assuming you don't feel like writing your own solver...).

这篇关于透视投影,4点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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