Ask Your Question

Revision history [back]

stitcher::stitch black output

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.