Ask Your Question

Problem when stitching images using stitcher module

asked 2013-10-29 00:01:43 -0600

ross shen gravatar image

updated 2013-10-29 02:05:36 -0600

Siegfried gravatar image

I tried to use the stitcher module in opencv to stitch images. Below is my code(core part).

int main()
    Mat img1 = imread("5.jpg");
    Mat img2 = imread("6.jpg");
    //Mat img3 = imread("11.jpg");

    Mat pano; // Mat to store the output pano image
    Stitcher stitcher = Stitcher::createDefault(try_use_gpu); // create a Stitcher object
    Stitcher::Status status = stitcher.stitch(imgs, pano); // stitch the input images together
    cout << "hello" <<endl;
    if (status != Stitcher::OK)
        cout << "Can't stitch images, error code = " << int(status) << endl;
        return -1;
    imwrite(result_name, pano); // write the result to the output image
    return 0;

"imgs" in the code above is a vector of Mat type. I saw a lot of similar codes as this in the net but I don't know why my code has a big limitation on the size of the input images. If the input images size is around 800 * 600, it works well. But when the size is 650 * 650 or 1280*640 or something else, the console prompt will just close very soon after the program ends. And not any images are saved on "panoResult.jpg". Also not any image is displayed. The visual studion 2010 is just displaying "Image_stitching2.exe: Native' has exited with code -1 (0xffffffff)." when I am debuging.

Can anyone helps with this? I really need to get progress on this since I have already spent several hours to fix it but just not correct. Any tips or help is great for me.

Thank you very much.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2015-02-25 20:41:54 -0600


The reason you are getting the error, or rather no result image is created, is due to the fact that stitcher parameters are created with default values in parameters.

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

I hope this will help you out.

edit flag offensive delete link more


Can you tell me which version of opencv have you used??

Sherlock gravatar imageSherlock ( 2017-01-24 08:45:28 -0600 )edit

Thank you! This helps me!

Peter01FE gravatar imagePeter01FE ( 2018-04-09 12:48:37 -0600 )edit

Question Tools


Asked: 2013-10-29 00:01:43 -0600

Seen: 5,483 times

Last updated: Oct 29 '13