Q: OpenCV image stitching does not work properly I'm a beginner programmer and just started using OpenCV.
I want to stitch together 2 images using OpenCV's stitching.cpp Sample program When I attempt to stitch the images, I either get a "Can't stitch images, error code = 1" or the images come out with a lot of black blank space. I've tried to create as much overlap as I can when taking the photos, and still that's the case.
Is there something wrong with the way I'm taking photos?
Here are examples of pictures that I took myself and their output:
Input images:


Output image:

This is a bad output. Notice the black space and how the image looks much different. There is a bit more to the output image that I was not able to show because imwrite did not save the file. I had to use imshow, then do a screen shot, but the image was too wide to capture in one screenshot. Regardless, still not a good output.
Here are example images I got online for another stitching program. These images  stitched together perfectly:


Output:


A: My guess after looking at above images is that the images which you have captured are too difficult to infer reliable matching. As you may know, stitching consists of:


*

*Finding keypoints 

*Matching keypoints by calculating distance between its corresponding descriptors 

*Some outlier detection process like RANSAC 

*Once you get matched keypoints, get homography. To get homography, you should at least have 8 pairs of matched keypoints. In reality, you may require more, since some outliers may not get removed. 


You are getting wrongly stitched images in one case, and the stitching is perfect for another pair of images, indicates that you have got the homography wrong. Homography depends on matched keypoints, thus that is where the real fault lies.
In the first set of images you have posted, both consist of keyboard. I would not be surprised if a keypoint detection and matching algorithm like SIFT matches the right-shift in the first image with the left-shift of the second computer in the second image. This is totally wrong and will mess up the homography. Similarly, the screen in the first image can be matched with the screen of the right side computer in the second image (it should have been matched with the left-side computer).
All of the above are my guesses, though I believe they are correct. Good way to confirm these would be to visualize matchings. Your image should not have a lot of repetitive and ambiguous patterns. For example, keyboard keys, small text on screen etc. 

A: Figured out the problem.
Had to reduce the resolution of my image. I guess the stitcher got confused with the excess of information when the resolution was too high.
Also the order in which the photos are given to the program matters. I have to sometimes have to flip the order.
