The error is somewhere in your capture process, not the stitching part. This code works fine (using these example images):
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/stitching/stitcher.hpp>
#include <iostream>
#include <vector>
using namespace std;
using namespace cv;
int main()
{
Mat fr1 = imread("a.jpg");
Mat fr2 = imread("b.jpg");
Mat pano;
vector<Mat> imgs;
Stitcher stitcher = Stitcher::createDefault(); // The value you entered here is the default
imgs.push_back(fr1);
imgs.push_back(fr2);
Stitcher::Status status = stitcher.stitch(imgs, pano);
if (status != Stitcher::OK)
{
cout << "Error stitching - Code: " <<int(status)<<endl;
return -1;
}
imshow("Frame 1", imgs[0]);
imshow("Frame 2", imgs[1]);
imshow("Stitched Image", pano);
waitKey();
return 0;
}
The error message Nik Bougalis dug up sounds like the stitcher can't connect the images. Are the images clear enough for the stitcher to find correspondences?
If you're sure they are, split your problem further to find the real error. Can you tweak the stitcher to work with still frames from your cameras? Are your cameras capturing correctly? Which type of image do they return?
On another note, stitching isn't very likely to work in real time, which makes your loop during capturing look a bit out of place. You might want to either capture your frames in advance and do it all in post-processing or expect a lot of manual optimization to get anywhere near a respectable frame rate.