2

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.

motiur
  • 1,640
  • 9
  • 33
  • 61
  • There is a good youtube video http://www.youtube.com/watch?v=fVJeJMWZcq8 which explains this ; however , a video is a video afterall . – motiur Nov 29 '13 at 02:21

2 Answers2

2

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

Michael Burdinov
  • 4,348
  • 1
  • 17
  • 28
  • I have obtained a 3x3 from the findHomography() function . I could make sense about what you said about the sensors . Now in order to get back to t2 , what should I do ? I think my function findHomography() handles about padding ones . – motiur Nov 28 '13 at 12:50
  • Just one more comment to settle out my ignorance . I am doing feature matching between two images ,so when I get a perfect match between image i1 and image i2 ,will the difference between x, x2 and y , y2 be zero. – motiur Nov 28 '13 at 14:06
  • In some theoretical perfect case - yes, in real case - highly unlikely. There always some error. Actually this is the reason findHomography accepting multiple points. Four pairs of points are required for definition of perspective transform (as I said its matrix has 8 degrees of freedom). Having more than 4 pairs of points allows findHomography to find more accurate transform despite the errors in point detection. – Michael Burdinov Nov 28 '13 at 17:27
1

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.

dagcilibili
  • 461
  • 5
  • 11
  • I worried about the use of 3xn points for 2d homography . I basically have two images to match , should I use 2d or 1d homography ? – motiur Nov 28 '13 at 11:11
  • You can use 2d homography after padding the vectors with the element 1 (which corresponds to using homogeneous scale factor of 1). For example, if one of the points you are using is `x = [x1; x2]` you put `x_pad = [x1; x2; 1]`. This can be used to match the images. – dagcilibili Nov 28 '13 at 11:54
  • What is the use of 1 , any idea ? – motiur Nov 28 '13 at 12:01
  • 1
    Homographic transform becomes a matrix multiplication when using homogenous coordinates. I think this is used to go from cartesian coordinates to homogenous coordinates. Though consulting a computer vision resource would be beneficial here. – dagcilibili Nov 28 '13 at 19:18