PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/toolkits/computer_vision/stitching.cpp

https://github.com/michaelkook/GraphLab-2
C++ | 120 lines | 83 code | 16 blank | 21 comment | 22 complexity | a677ebca0a5b85e7aec6d6180b1d6642 MD5 | raw file
Possible License(s): ISC, Apache-2.0
  1. /*
  2. * Copyright (c) 2009 Carnegie Mellon University.
  3. * All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing,
  12. * software distributed under the License is distributed on an "AS
  13. * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  14. * express or implied. See the License for the specific language
  15. * governing permissions and limitations under the License.
  16. *
  17. * For more about this software visit:
  18. *
  19. * http://www.graphlab.ml.cmu.edu
  20. *
  21. */
  22. #include <iostream>
  23. #include <fstream>
  24. #include "opencv2/highgui/highgui.hpp"
  25. #include "opencv2/stitching/stitcher.hpp"
  26. using namespace std;
  27. using namespace cv;
  28. bool try_use_gpu = false;
  29. vector<Mat> imgs;
  30. string result_name = "result.png";
  31. void printUsage();
  32. int parseCmdArgs(int argc, char** argv);
  33. int main(int argc, char* argv[])
  34. {
  35. int retval = parseCmdArgs(argc, argv);
  36. if (retval) return -1;
  37. Mat pano;
  38. Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
  39. Stitcher::Status status = stitcher.stitch(imgs, pano);
  40. if (status != Stitcher::OK)
  41. {
  42. cout << "Can't stitch images, error code = " << status << endl;
  43. return -1;
  44. }
  45. imwrite(result_name, pano);
  46. return 0;
  47. }
  48. void printUsage()
  49. {
  50. cout <<
  51. "Rotation model images stitcher.\n\n"
  52. "stitching img1 img2 [...imgN]\n\n"
  53. "Flags:\n"
  54. " --try_use_gpu (yes|no)\n"
  55. " Try to use GPU. The default value is 'no'. All default values\n"
  56. " are for CPU mode.\n"
  57. " --output <result_img>\n"
  58. " The default is 'result.jpg'.\n";
  59. }
  60. int parseCmdArgs(int argc, char** argv)
  61. {
  62. if (argc == 1)
  63. {
  64. printUsage();
  65. return -1;
  66. }
  67. for (int i = 1; i < argc; ++i)
  68. {
  69. if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
  70. {
  71. printUsage();
  72. return -1;
  73. }
  74. else if (string(argv[i]) == "--try_use_gpu")
  75. {
  76. if (string(argv[i + 1]) == "no")
  77. try_use_gpu = false;
  78. else if (string(argv[i + 1]) == "yes")
  79. try_use_gpu = true;
  80. else
  81. {
  82. cout << "Bad --try_use_gpu flag value\n";
  83. return -1;
  84. }
  85. i++;
  86. }
  87. else if (string(argv[i]) == "--output")
  88. {
  89. result_name = argv[i + 1];
  90. i++;
  91. }
  92. else
  93. {
  94. Mat img = imread(argv[i]);
  95. if (img.empty())
  96. {
  97. cout << "Can't read image '" << argv[i] << "'\n";
  98. return -1;
  99. }
  100. imgs.push_back(img);
  101. }
  102. }
  103. return 0;
  104. }