I'm trying to stitch 2 images just for start for panography. I"ve already found keypoints, found homography using RANSAC but I can't figure out how to align these 2 images (i'm new at opencv). Now part of code
vector<Point2f> points1, points2;
for( int i = 0; i < good_matches.size(); i++ )
{
//-- Get the keypoints from the good matches
points1.push_back( keypoints1[ good_matches[i].queryIdx ].pt );
points2.push_back( keypoints2[ good_matches[i].trainIdx ].pt );
}
/* Find Homography */
Mat H = findHomography( Mat(points2), Mat(points1), CV_RANSAC );
/* warp the image */
warpPerspective(mImg2, warpImage2, H, Size(mImg2.cols*2, mImg2.rows*2), INTER_CUBIC);
and I need to stitch Mat mImg1
where is loaded the first image and Mat warpImage2
where is the warped second image. Can you pls show me how to do that? I also have the warped image cut up and I know I have to change the homography matrix but for now I need to align these two images. Thank you for helping.
Edit: With Martin Beckett's help I added this code
//Point a cv::Mat header at it (no allocation is done)
Mat final(Size(mImg2.cols*2 + mImg1.cols, mImg2.rows*2),CV_8UC3);
//velikost img1
Mat roi1(final, Rect(0, 0, mImg1.cols, mImg1.rows));
Mat roi2(final, Rect(0, 0, warpImage2.cols, warpImage2.rows));
warpImage2.copyTo(roi2);
mImg1.copyTo(roi1);
imshow("final", final);
and it's working now
See Question&Answers more detail:os