Question

I am transforming image2 with respect to image1 using 'warpperspective' function of opencv.

the ourput image is as below. Can anybody tell me how I can know the co-ordinate corner pointed below in the image?

the code for warprospective is as follows -

 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);
imshow("resut",result1);


...
}

Thanks.

Was it helpful?

Solution

In order to find the coordinates of the corners of the warped image, you can do the following:

cv::Mat_<float> p(3,1), c_topleft, c_topright, c_botleft, c_botright;

p(0)=0; p(1)=0; p(2)=1;
c_topleft=H1*p; c_topleft/=c_topleft(2); // Top-Left corner

p(0)=input2.cols-1; p(1)=0; p(2)=1;
c_topright=H1*p; c_topright/=c_topright(2); // Top-right corner

p(0)=0; p(1)=input2.rows-1; p(2)=1;
c_botleft=H1*p; c_botleft/=c_botleft(2); // Bottom-left corner

p(0)=input2.cols-1; p(1)=input2.rows-1; p(2)=1;
c_botright=H1*p; c_botright/=c_botright(2); // Bottom-right corner
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top