Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Calculate affine transformation matrix

I want to build a function that can estimate geometric transform i.e calculate the transformation matrix required to convert first image into second image.

So my second image is obtained in two steps,

  1. Resize the first image to 0.7 in both x & y directions
  2. Rotate the resized image at an angle of 31 degrees.

So I need use the getAffineTransform function to calculate the transformation matrix, but the function doesn't take Mat objects as parameters. So i decided to find the best matched features and stored in a Dmatch object.

But now I am confused as to how to pass this as parameters to the getAffineTransform function as it requires Point2f type? Or is it possible to use Mat object as parameters to this function?

source code and image used

Calculate affine transformation matrix

I want to build a function that can estimate geometric transform i.e calculate the transformation matrix required to convert first image into second image.

So my second image is obtained in two steps,

  1. Resize the first image to 0.7 in both x & y directions
  2. Rotate the resized image at an angle of 31 degrees.

So I need use the getAffineTransform function to calculate the transformation matrix, but the function doesn't take Mat objects as parameters. So i decided to find the best matched features and stored in a Dmatch object.

But now I am confused as to how to pass this as parameters to the getAffineTransform function as it requires Point2f type? Or is it possible to use Mat object as parameters to this function?

source code and image used

//queryidx- keypoints1
//traindidx-  keypoints2
vector<Point2f> a,b;

for(int i=0;i<good_matches.size();i++)
{
a.push_back( keypoints_1[good_matches[i].queryIdx].pt );
b.push_back( keypoints_2[good_matches[i].trainIdx].pt );
}

Mat M = getAffineTransform( Mat(a), Mat(b)  );