0
votes

can somebody help me, how we can calculate the new positions of keypoints in the transformed image,the keypoints were detected in original image. I am using opencv homography matrix and warpPerspective to make the transformed image.

Here is a code..

...
 std::vector< Point2f > points1,points2;
 for( int i = 0; i < matches1.size(); i++ )
    {
     points1.push_back( keypoints_input1[matches1[i].queryIdx ].pt );
     points2.push_back( keypoints_input2[matches1[i].trainIdx ].pt );
    }
 /* Find the Homography Matrix for current and next frame*/
 Mat H1 = findHomography( points2, points1, CV_RANSAC );
 /* Use the Homography Matrix to warp the images*/
cv::Mat result1;
warpPerspective(input2, result1, H1, Size(input2.cols+150, input2.rows+150),              
INTER_CUBIC);
...
}

Now I want to calculate the new positions of points2 in the result1 image.

For example in the below transformed image , we know the corner points. Now I want to calculate the new position of the keypoints say before transformation {(x1,y1),(x2,y2),(x3,y3)...}, How we can calculate it?

Update: opencv 'perspectiveTransform' does what I trying to do.

1
this is a question about mathematics and transformations; not about programming...Chris Maes
@Chris Maes, computer-vision is about programming mathematic transformationsberak
ok you have a point, my comment was maybe not clear enough. but this question is clearly a "how to do my math" question and not a programmatic question, no?Chris Maes
@ChrisMaes , Thanks for your comment, I really don't know, how to do it that is why I am asking. I don't think anything is wrong in asking people who knows about it.MMH
@MMH I didn't want to be rude. I understand your question but you'd better paste 5 lines of code on how you wrap your image and where exactly you are stuck; that is a lots easier to answer... my opinion maybeChris Maes

1 Answers

2
votes

Let's call I' the image obtained by warping image I using homography H.

If you extracted keypoints mi = (xi, yi, 1) in original image I, you can get the keypoints m'i in the warped image I' using the homography transform: S * m'i = H * mi. Notice the scale factor S, if you want the keypoints coordinates in pixels, you have to scale m'i so that the third element is 1.

If you want to understand where the scale factor comes from, have a look at Homogeneous Coordinates.

Also, there is an OpenCV function to apply this transformation to an array of points: perspectiveTransform(documentation).