/toolkits/computer_vision/stitching.cpp
C++ | 120 lines | 83 code | 16 blank | 21 comment | 22 complexity | a677ebca0a5b85e7aec6d6180b1d6642 MD5 | raw file
Possible License(s): ISC, Apache-2.0
- /*
- * Copyright (c) 2009 Carnegie Mellon University.
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an "AS
- * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
- * express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- *
- * For more about this software visit:
- *
- * http://www.graphlab.ml.cmu.edu
- *
- */
- #include <iostream>
- #include <fstream>
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/stitching/stitcher.hpp"
- using namespace std;
- using namespace cv;
- bool try_use_gpu = false;
- vector<Mat> imgs;
- string result_name = "result.png";
- void printUsage();
- int parseCmdArgs(int argc, char** argv);
- int main(int argc, char* argv[])
- {
- int retval = parseCmdArgs(argc, argv);
- if (retval) return -1;
- Mat pano;
- Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
- Stitcher::Status status = stitcher.stitch(imgs, pano);
- if (status != Stitcher::OK)
- {
- cout << "Can't stitch images, error code = " << status << endl;
- return -1;
- }
- imwrite(result_name, pano);
- return 0;
- }
- void printUsage()
- {
- cout <<
- "Rotation model images stitcher.\n\n"
- "stitching img1 img2 [...imgN]\n\n"
- "Flags:\n"
- " --try_use_gpu (yes|no)\n"
- " Try to use GPU. The default value is 'no'. All default values\n"
- " are for CPU mode.\n"
- " --output <result_img>\n"
- " The default is 'result.jpg'.\n";
- }
- int parseCmdArgs(int argc, char** argv)
- {
- if (argc == 1)
- {
- printUsage();
- return -1;
- }
- for (int i = 1; i < argc; ++i)
- {
- if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
- {
- printUsage();
- return -1;
- }
- else if (string(argv[i]) == "--try_use_gpu")
- {
- if (string(argv[i + 1]) == "no")
- try_use_gpu = false;
- else if (string(argv[i + 1]) == "yes")
- try_use_gpu = true;
- else
- {
- cout << "Bad --try_use_gpu flag value\n";
- return -1;
- }
- i++;
- }
- else if (string(argv[i]) == "--output")
- {
- result_name = argv[i + 1];
- i++;
- }
- else
- {
- Mat img = imread(argv[i]);
- if (img.empty())
- {
- cout << "Can't read image '" << argv[i] << "'\n";
- return -1;
- }
- imgs.push_back(img);
- }
- }
- return 0;
- }