Reputation: 1346
It is first time when I am using OpenCV, and that is for made a simple image stitching ... and I was tried the following simple code:
Mat resImage;
Mat image1 = imread(_T("D:\\Tempx\\Image1.bmp"), CV_LOAD_IMAGE_COLOR);
Mat image2 = imread(_T("D:\\Tempx\\Image2.bmp"), CV_LOAD_IMAGE_COLOR);
std::vector<cv::Mat> vImg;
vImg.push_back(image1);
vImg.push_back(image2);
Stitcher stitcher = Stitcher::createDefault(TRUE);
Stitcher::Status stat = stitcher.stitch(vImg, resImage); // <-- crash the program !!!
if(cv::Stitcher::OK != stat)
sError.Format(_T("Error while stitching the images."));
std::vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
compression_params.push_back(9);
imwrite(_T("D:\\Tempx\\Image3.bmp"), resImage, compression_params);
but on line:
stitcher.stitch(vImg, resImage);
the program has crashed:
might be something simple, might be not ... could you take a look and tell me a hint/idea, anything ? Thank you.
Upvotes: 2
Views: 430
Reputation: 14530
I'm guessing something is wrong with your images. Make sure they are read correctly, e.g., by imwrite into new files. Also test with another pair of images first. If all those pass, then probably it fails to estimate the camera parameters for some reason.
Update: It seems the feature extractor has an issue, difficult to tell what's gone wrong with just the trace back you've posted. Set the feature extractor in the code and see how it goes:
Stitcher stitch = Stitcher::createDefault(FALSE);
stitch.setFeaturesFinder(new detail::OrbFeaturesFinder());
The first line is the same as in your code, in the second line we just tell the stitcher what feature extractor to use.
Upvotes: 1
Reputation: 1346
and
and the code is:
#include <opencv2/opencv.hpp>
#include <opencv2/stitching.hpp>
Mat image1 = imread(_T("D:/Tempx/Image1.bmp"), CV_LOAD_IMAGE_ANYCOLOR);
Mat image2 = imread(_T("D:/Tempx/Image2.bmp"), CV_LOAD_IMAGE_ANYCOLOR);
vImg.push_back(image1);
vImg.push_back(image2);
Mat resImage;
Stitcher stitch = Stitcher::createDefault(FALSE);
Stitcher::Status stat = stitch.stitch(vImg, resImage);
if(Stitcher::OK != stat)
MessageBox(_T("Error while stitching the images."));
std::vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
compression_params.push_back(9);
imwrite(_T("D:/Tempx/Image3.bmp"), resImage, compression_params);
Upvotes: 0