Perspective Transform in Matlab

∥☆過路亽.° 提交于 2019-12-24 00:16:19

问题


Lets say :

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]

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.


回答1:


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.

Edit (answer to comment):

xTag = M11*x1 + M12*y2 + M13

yTag = M21*x1 + M22*y2 + M23

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

x2 = xTag/zTag

y2 = yTag/zTag




回答2:


You can use the functions homography2d.m and homoTrans.m found at Peter Kovesi's site on MATLAB and Octave Functions for Computer Vision and Image Processing to find the homography and apply the transformation.



来源:https://stackoverflow.com/questions/20261228/perspective-transform-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!