Stitching multiple images - adding a third image

I am trying to stitch a third image after stitching two images together, but it doesn't work.

To develop, I successfully stitched two images together using the code given in the opencv documentation ( http://docs.opencv.org/doc/tutorials/features2d/feature_homography/feature_homography.html ) and got this image. http://i.stack.imgur.com/gqQjV.jpg

Then, after a lot of reading and ROI problems, I removed the black parts of the image to get this image. enter image description here

Now I'm trying to stitch a third image ( http://i.stack.imgur.com/nXD86.jpg ) to this one using the same code, but stitching doesn't work. Feature matching works great.

enter image description here

But after running the program, I get the same image with a larger black area (due to the ROI) and no third image. (Output: http://i.stack.imgur.com/WzZA0.jpg )

I figured it had something to do with the tiny black bar at the end of the stitched image, so the WarpPerspective statement does not display the stitched area. Code:

Mat result;
warpPerspective(img_scene, result, H, Size(img_scene.cols*2, img_scene.rows*2), INTER_CUBIC);
Mat final(Size(img_scene.cols + img_object.cols, img_scene.rows*2),CV_8UC3);

Mat roi1(final, Rect(0, 0,  img_object.cols, img_object.rows));
Mat roi2(final, Rect(0, 0, result.cols, result.rows));
result.copyTo(roi2);
img_object.copyTo(roi1);

      

The warpperspective result gives a black image instead of the remaining area.

Can someone please tell me where I can go wrong and how to fix it? Thanks to

+3


source to share


1 answer


First of all, your

Mat final(Size(img_scene.cols + img_object.cols, img_scene.rows*2),CV_8UC3);

      

should become

Mat final(Size(img_scene.cols + img_object.cols, img_scene.rows),CV_8UC3);

      



since you don't need to increase the height.

Now, to copy from ROI, don't forget to overwrite. Will this work instead?

Mat roi2(final, Rect(img_object.cols, 0, img_object.cols + result.cols, img_object.rows));

      

+1


source







All Articles