Reputation: 789
I am trying to stitch a third image after stitching two images together but it doesn't seem to work.
To elaborate, 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 obtained this image. https://i.sstatic.net/gqQjV.jpg
Then, after a lot of reading and issues with the ROI, i removed the black portions of the image to obtain this image.
Now, I'm trying to stitch a third image (https://i.sstatic.net/nXD86.jpg) to this using the same code but the stitching doesn't work. The feature matching works perfectly.
But after executing the program, I obtain the same image with a larger black area (due to the ROI) and without the third image. (Output:https://i.sstatic.net/WzZA0.jpg)
I figured it has something to do with the tiny black strip at the end of the stitched image so the WarpPerspective statement doesn't map a stitched area. The 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 result of warpperspective gives a black image instead of the remaining region.
Can someone please tell me where I might be going wrong and how to fix it? Thanks
Upvotes: 3
Views: 2566
Reputation: 3047
First of all your
Mat final(Size(img_scene.cols + img_object.cols, img_scene.rows*2),CV_8UC3);
must become
Mat final(Size(img_scene.cols + img_object.cols, img_scene.rows),CV_8UC3);
since you don't have to increase the height.
Now for copying with ROI, make sure to not overwrite. Would this work instead?
Mat roi2(final, Rect(img_object.cols, 0, img_object.cols + result.cols, img_object.rows));
Upvotes: 1