Matlab中的透视变换 [英] Perspective Transform in Matlab

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

问题描述

让我们说:

point1 = [1 2 3 4 5 ; 1 2 3 4 5 ];
point2 = [2 3 4 5 6 ; 2 3 4 5 6 ];

s = findHomography(points1,points2);

Coordinates of an object containing points1 are [0,0; 10,0; 0,10; 10,10]

如何找到对象上的计算透视变换,以便将其变换为测试坐标. opencv中有内置的函数可以执行此操作,但是,我确实需要一个简单的示例来清除我的困惑.谢谢.

How do I find calculate perspective transform on the object so that it transforms to my test coordinates. There are built in function in opencv that can do this , however , I really need a simple example to clear out my confusion . Thanks.

推荐答案

透视变换不是线性变换.因此,矩阵M 2x2不能使w = M * v(从第一平面开始的点v =(x1,y1)和从第二平面开始的点w =(x2,y2)).但是,如果您使用同质坐标",则可以做到这一点.齐次坐标中的2d点看起来像(x,y,1).或者在更一般的情况下(x,y,z)等于(x/z,y/z,1).如果您考虑如何将3d场景中的点投影到相机的2d传感器上,则此表示法很有意义.在齐次坐标中,矩阵M实际上存在3 x3,并且w = M * v.因此,当您进行从2d到2d的透视转换时,应该期望有3x3的矩阵和3xn的点.

Perspective transform is not a linear transformation. So you can't have matrix M 2x2 such that w=M*v (point v=(x1,y1) from first plane and point w=(x2,y2) from second plane). But you can do the trick if you use "homogeneous coordinates". 2d point in homogeneous coordinates looks like (x,y,1). Or in more general case (x,y,z) is equivalent to (x/z,y/z,1). This notation makes sense if you think about how points from 3d scene are projected to 2d sensor of the camera. In homogeneous coordinates matrix M 3x3 actually exists and w=M*v. So when you are working with perspective transformation from 2d to 2d you should expect to have 3x3 matrices and 3xn points.

编辑(回答评论):

xTag = M11 * x1 + M12 * y2 + M13

xTag = M11*x1 + M12*y2 + M13

yTag = M21 * x1 + M22 * y2 + M23

yTag = M21*x1 + M22*y2 + M23

zTag = M31 * x1 + M32 * y2 + M33(M33始终等于1,因为只有8个自由度)

zTag = M31*x1 + M32*y2 + M33 (M33 will always be equal to 1, since there only 8 degrees of freedom)

x2 = xTag/zTag

x2 = xTag/zTag

y2 = yTag/zTag

y2 = yTag/zTag

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

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