stitcher::stitch black output [closed]

asked 2016-04-29 19:16:36 -0500

bhan gravatar image

I'm trying to use stitcher::stitch to stitch two images. I have tested my code with many images, but each time the output image is just a black image. The code that I have put together is:

#include <stdio.h>
#include <iostream>

#include "opencv2/stitching.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/xfeatures2d/nonfree.hpp"
#include "opencv2/xfeatures2d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;
using namespace cv::xfeatures2d;

int main() {
    Mat imageNow;
    std::vector<Mat> myImages;
    Mat im1 = imread("panorama_image1.jpg");
    Mat im2 = imread("panorama_image2.jpg");
    if (!im1.data || !im2.data) {
        std::cout << "There was a problem reading one or more images." << std::endl;
        return -1;
    }
    myImages.push_back(im1);
    myImages.push_back(im2);
    Stitcher stitcher = Stitcher::createDefault();
    Mat myPanorama;
    stitcher.stitch(myImages, myPanorama);
    imwrite("myPanorama.jpg", myPanorama);
    return 0;
}

Can anyone suggest an improvement? Thanks.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2016-04-30 04:33:06.885177

Comments

1

There is no problem with your program. Try :

std::cout<<stitcher.stitch(myImages, myPanorama);
LBerger gravatar imageLBerger ( 2016-04-30 03:05:10 -0500 )edit

Thanks @LBerger. I made the change you suggested, but it didn't change the result.

bhan gravatar imagebhan ( 2016-04-30 03:33:00 -0500 )edit

Of course but what is value in stdout (error number in stitcher class)?

LBerger gravatar imageLBerger ( 2016-04-30 03:53:29 -0500 )edit

I'm getting the stdout value 0.

bhan gravatar imagebhan ( 2016-04-30 03:57:59 -0500 )edit

Can you use this two images?

LBerger gravatar imageLBerger ( 2016-04-30 04:04:31 -0500 )edit

No the result does not change when I use those images. I am able to run a modified version (updated to OpenCV 3.0 syntax) of the code at that link (which of course doesn't use stitcher), but my code continues to generate a blank, black image.

bhan gravatar imagebhan ( 2016-04-30 04:07:37 -0500 )edit

What is your opencv version and your OS?

LBerger gravatar imageLBerger ( 2016-04-30 04:09:50 -0500 )edit

I'm running opencv 3.1.0 on OS X 10.11.4.

bhan gravatar imagebhan ( 2016-04-30 04:18:29 -0500 )edit

insert

#include "opencv2/core/ocl.hpp"

and before Mat imagenow; :

cv::ocl::setUseOpenCL(false);
LBerger gravatar imageLBerger ( 2016-04-30 04:25:27 -0500 )edit

That did the trick. Thank you.

bhan gravatar imagebhan ( 2016-04-30 04:28:24 -0500 )edit