Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
597 views
in Technique[技术] by (71.8m points)

c++ - Stitching 2 images in opencv

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You create a new larger image of the correct combined size, then make ROIs of the size of the existing images in the positions you want them in the final image and copy the existing images to the ROIs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...