opencv_version.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include <iostream>
  5. #include <opencv2/core.hpp>
  6. #include <opencv2/core/utils/trace.hpp>
  7. #include <opencv2/core/opencl/opencl_info.hpp>
  8. #ifdef OPENCV_WIN32_API
  9. #define WIN32_LEAN_AND_MEAN
  10. #include <windows.h>
  11. #endif
  12. // defined in core/private.hpp
  13. namespace cv {
  14. CV_EXPORTS const char* currentParallelFramework();
  15. }
  16. static void dumpHWFeatures(bool showAll = false)
  17. {
  18. std::cout << "OpenCV's HW features list:" << std::endl;
  19. int count = 0;
  20. for (int i = 0; i < CV_HARDWARE_MAX_FEATURE; i++)
  21. {
  22. cv::String name = cv::getHardwareFeatureName(i);
  23. if (name.empty())
  24. continue;
  25. bool enabled = cv::checkHardwareSupport(i);
  26. if (enabled)
  27. count++;
  28. if (enabled || showAll)
  29. {
  30. printf(" ID=%3d (%s) -> %s\n", i, name.c_str(), enabled ? "ON" : "N/A");
  31. }
  32. }
  33. std::cout << "Total available: " << count << std::endl;
  34. }
  35. static void dumpParallelFramework()
  36. {
  37. const char* parallelFramework = cv::currentParallelFramework();
  38. if (parallelFramework)
  39. {
  40. int threads = cv::getNumThreads();
  41. std::cout << "Parallel framework: " << parallelFramework << " (nthreads=" << threads << ")" << std::endl;
  42. }
  43. }
  44. int main(int argc, const char** argv)
  45. {
  46. CV_TRACE_FUNCTION();
  47. CV_TRACE_ARG(argc);
  48. CV_TRACE_ARG_VALUE(argv0, "argv0", argv[0]);
  49. CV_TRACE_ARG_VALUE(argv1, "argv1", argv[1]);
  50. #ifndef OPENCV_WIN32_API
  51. cv::CommandLineParser parser(argc, argv,
  52. "{ help h usage ? | | show this help message }"
  53. "{ verbose v | | show build configuration log }"
  54. "{ opencl | | show information about OpenCL (available platforms/devices, default selected device) }"
  55. "{ hw | | show detected HW features (see cv::checkHardwareSupport() function). Use --hw=0 to show available features only }"
  56. "{ threads | | show configured parallel framework and number of active threads }"
  57. );
  58. if (parser.has("help"))
  59. {
  60. parser.printMessage();
  61. return 0;
  62. }
  63. if (parser.has("verbose"))
  64. {
  65. std::cout << cv::getBuildInformation().c_str() << std::endl;
  66. }
  67. else
  68. {
  69. std::cout << CV_VERSION << std::endl;
  70. }
  71. if (parser.has("opencl"))
  72. {
  73. cv::dumpOpenCLInformation();
  74. }
  75. if (parser.has("hw"))
  76. {
  77. dumpHWFeatures(parser.get<bool>("hw"));
  78. }
  79. if (parser.has("threads"))
  80. {
  81. dumpParallelFramework();
  82. }
  83. #else
  84. std::cout << cv::getBuildInformation().c_str() << std::endl;
  85. cv::dumpOpenCLInformation();
  86. dumpHWFeatures();
  87. dumpParallelFramework();
  88. MessageBoxA(NULL, "Check console window output", "OpenCV(" CV_VERSION ")", MB_ICONINFORMATION | MB_OK);
  89. #endif
  90. return 0;
  91. }