compute_descriptors.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2014, Biagio Montesano, all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of the copyright holders may not be used to endorse or promote products
  27. // derived from this software without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors "as is" and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall the Intel Corporation or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. // (including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort (including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. //M*/
  41. #include <iostream>
  42. #include <opencv2/opencv_modules.hpp>
  43. #ifdef HAVE_OPENCV_FEATURES2D
  44. #include <opencv2/line_descriptor.hpp>
  45. #include <opencv2/core/utility.hpp>
  46. #include <opencv2/imgproc.hpp>
  47. #include <opencv2/features2d.hpp>
  48. #include <opencv2/highgui.hpp>
  49. using namespace cv;
  50. using namespace cv::line_descriptor;
  51. static const char* keys =
  52. { "{@image_path | | Image path }" };
  53. static void help()
  54. {
  55. std::cout << "\nThis example shows the functionalities of lines extraction " << "and descriptors computation furnished by BinaryDescriptor class\n"
  56. << "Please, run this sample using a command in the form\n" << "./example_line_descriptor_compute_descriptors <path_to_input_image>"
  57. << std::endl;
  58. }
  59. int main( int argc, char** argv )
  60. {
  61. /* get parameters from command line */
  62. CommandLineParser parser( argc, argv, keys );
  63. String image_path = parser.get<String>( 0 );
  64. if( image_path.empty() )
  65. {
  66. help();
  67. return -1;
  68. }
  69. /* load image */
  70. cv::Mat imageMat = imread( image_path, 1 );
  71. if( imageMat.data == NULL )
  72. {
  73. std::cout << "Error, image could not be loaded. Please, check its path" << std::endl;
  74. }
  75. /* create a binary mask */
  76. cv::Mat mask = Mat::ones( imageMat.size(), CV_8UC1 );
  77. /* create a pointer to a BinaryDescriptor object with default parameters */
  78. Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor();
  79. /* compute lines */
  80. std::vector<KeyLine> keylines;
  81. bd->detect( imageMat, keylines, mask );
  82. /* compute descriptors */
  83. cv::Mat descriptors;
  84. bd->compute( imageMat, keylines, descriptors);
  85. }
  86. #else
  87. int main()
  88. {
  89. std::cerr << "OpenCV was built without features2d module" << std::endl;
  90. return 0;
  91. }
  92. #endif // HAVE_OPENCV_FEATURES2D