Calculating new positions of keypoints

流过昼夜 提交于 2019-12-25 12:13:16

问题


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:


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).



来源:https://stackoverflow.com/questions/22472871/calculating-new-positions-of-keypoints

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