Ask Your Question
0

Problems using Stitcher::stich

asked 2014-11-10 06:13:48 -0600

rafafirenze gravatar image

updated 2014-11-11 09:48:19 -0600

Hello.

I'm trying to use Stitcher::Status as this example:

vector<Mat> imgs;
// I add images...
Mat pano;
Stitcher stitcher = Stitcher::createDefault(false);
Stitcher::Status status = stitcher.stitch(imgs, pano);
cout << endl << status << endl;

The printed result is "0". But I get a 1x1 black pixel image.

Sometimes, if I remove one image from the vector<Mat> I get a result, but if I add more it doesn't work.

I'm taking pictures as panorama, but with createPanorama I get an Assertion error:

imgs.size() == imgs_.size()

What am I doing bad? Thank you.

Update:

I'm trying to add rois taking the 50% of every image. For the first image I take the right 50%. For the last, the left 50%, and for the rest I take 50% of left and 50% of right:

vector<Mat> imgs;
imgs.push_back(imread("/Users/myImages/IMG_0073.jpg"));
imgs.push_back(imread("/Users/myImages/IMG_0074.jpg"));
imgs.push_back(imread("/Users/myImages/IMG_0075.jpg"));
imgs.push_back(imread("/Users/myImages/IMG_0076.jpg"));
imgs.push_back(imread("/Users/myImages/IMG_0077.jpg"));
imgs.push_back(imread("/Users/myImages/IMG_0078.jpg"));

processImage(imgs);

and my function is:

void processImage(vector imgs){

vector<vector<Rect>> rois;
vector<Rect> roisVect;
for (int j = 0; j < imgs.size(); j++) {
    if (j == 0) {
        Rect rect1 = Rect(imgs.at(j).cols*50/100, 0, imgs.at(j).cols*50/100,imgs.at(j).rows);
        roisVect.push_back(rect1);
        rois.push_back(roisVect);

        roisVect.clear();
    } else if (j == imgs.size() - 1) {
        Rect rect2 = Rect(0, 0, imgs.at(j).cols*50/100, imgs.at(j).rows);
        roisVect.push_back(rect2);
        rois.push_back(roisVect);

        roisVect.clear();
    } else {
        Rect rect3 = Rect(imgs.at(j).cols*50/100, 0, imgs.at(j).cols*50/100, imgs.at(j).rows);
        Rect rect4 = Rect(0, 0, imgs.at(j).cols*50/100, imgs.at(j).rows);
        roisVect.push_back(rect4);
        roisVect.push_back(rect3);
        rois.push_back(roisVect);

        roisVect.clear();
    }

}
Mat pano;
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status = stitcher.stitch(imgs, rois, pano);
cout << endl << status;
cout << endl << pano.size();
if (!pano.empty())
    imshow("pano", pano);
waitKey(10);

imwrite("/Users/myImages/final" + to_string(imgs.size()) + ".jpg", pano);
}

And my results (cout) are:

0 // (OK)

[1 x 1]

edit retag flag offensive close merge delete

Comments

I have the same problem. I tried the opencv-2.4.10/build/bin/cpp-example-stitching_detailed example and it only works with small images (ca. 800x600) With bigger images it only writes empty panos and the exits with the code 255. But interestingly a few weeks ago with the same example I could stitch around 10 images (2704x1440 in size).

wagp11 gravatar imagewagp11 ( 2015-01-22 10:20:16 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2015-02-25 22:20:51 -0600

The reason you are getting the error, or rather no result image is created, in your case small pixel sized black image is due to the fact that stitcher parameters are created with default values in parameters. Here the resolution acceptance ratio is set to 0.6 as default, but you require it to be flexible,

That is why, just after the line

Stitcher stitcher = Stitcher::createDefault(try_use_gpu);

add these

stitcher.setRegistrationResol(-1); /// 0.6
stitcher.setSeamEstimationResol(-1);   /// 0.1
stitcher.setCompositingResol(-1);   //1
stitcher.setPanoConfidenceThresh(-1);   //1
stitcher.setWaveCorrection(true);
stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);

I hope this will help you out.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-11-10 06:13:48 -0600

Seen: 1,316 times

Last updated: Feb 25 '15