Skip to content

Instantly share code, notes, and snippets.

@Reflejo
Created July 7, 2016 07:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Reflejo/3edb48773540609b84cb901c90a7d59a to your computer and use it in GitHub Desktop.
Save Reflejo/3edb48773540609b84cb901c90a7d59a to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <string>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/opencv_modules.hpp>
#include <opencv2/stitching.hpp>
#include <opencv2/stitching/detail/warpers.hpp>
using namespace std;
using namespace cv;
using namespace cv::detail;
int main(int argc, char* argv[]) {
int imageCount = argc - 2;
if (imageCount < 2) {
cout << argv[0] << " <image1> <image2> ... <imageN> <output path>";
return -1;
}
vector<Mat> images(imageCount);
for (int i = 0; i < imageCount; ++i) {
Mat image = imread(argv[i + 1]);
if (image.empty()) {
cout << "Error opening image " << argv[i] << "\n";
return -1;
}
cout << "Loading image: " << argv[i + 1] << "\n";
images[i] = image.clone();
}
Stitcher stitcher = Stitcher::createDefault(true);
stitcher.setRegistrationResol(1.5);
stitcher.setSeamEstimationResol(0.3);
stitcher.setCompositingResol(2.0);
stitcher.setPanoConfidenceThresh(0.4);
stitcher.setWarper(makePtr<cv::CylindricalWarper>());
stitcher.setSeamFinder(makePtr<detail::VoronoiSeamFinder>());
stitcher.setFeaturesFinder(makePtr<detail::SurfFeaturesFinder>());
Mat result;
stitcher.stitch(images, result);
cout << "Saving file: " << argv[argc - 1] << "\n";
imwrite(argv[argc - 1], result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment