test_plugins.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 "test_precomp.hpp"
  5. namespace opencv_test { namespace {
  6. enum VideoBackendMode
  7. {
  8. MODE_CAMERA,
  9. MODE_STREAM,
  10. MODE_WRITER,
  11. };
  12. static
  13. void dumpBackendInfo(VideoCaptureAPIs backend, enum VideoBackendMode mode)
  14. {
  15. std::string name;
  16. try
  17. {
  18. name = videoio_registry::getBackendName(backend);
  19. }
  20. catch (const std::exception& e)
  21. {
  22. ADD_FAILURE() << "Can't query name of backend=" << backend << ": " << e.what();
  23. }
  24. catch (...)
  25. {
  26. ADD_FAILURE() << "Can't query name of backend=" << backend << ": unknown C++ exception";
  27. }
  28. bool isBuiltIn = true;
  29. try
  30. {
  31. isBuiltIn = videoio_registry::isBackendBuiltIn(backend);
  32. }
  33. catch (const std::exception& e)
  34. {
  35. ADD_FAILURE() << "Failed isBackendBuiltIn(backend=" << backend << "): " << e.what();
  36. cout << name << " - UNKNOWN TYPE" << endl;
  37. return;
  38. }
  39. if (isBuiltIn)
  40. {
  41. cout << name << " - BUILTIN" << endl;
  42. return;
  43. }
  44. std::string description = "NO_DESCRIPTION";
  45. int version_ABI = 0;
  46. int version_API = 0;
  47. try
  48. {
  49. if (mode == MODE_CAMERA)
  50. description = videoio_registry::getCameraBackendPluginVersion(backend, version_ABI, version_API);
  51. else if (mode == MODE_STREAM)
  52. description = videoio_registry::getStreamBackendPluginVersion(backend, version_ABI, version_API);
  53. else if (mode == MODE_WRITER)
  54. description = videoio_registry::getWriterBackendPluginVersion(backend, version_ABI, version_API);
  55. else
  56. CV_Error(Error::StsInternal, "");
  57. cout << name << " - PLUGIN (" << description << ") ABI=" << version_ABI << " API=" << version_API << endl;
  58. return;
  59. }
  60. catch (const cv::Exception& e)
  61. {
  62. if (e.code == Error::StsNotImplemented)
  63. {
  64. cout << name << " - PLUGIN - NOT LOADED" << endl;
  65. return;
  66. }
  67. ADD_FAILURE() << "Failed getBackendPluginDescription(backend=" << backend << "): " << e.what();
  68. }
  69. catch (const std::exception& e)
  70. {
  71. ADD_FAILURE() << "Failed getBackendPluginDescription(backend=" << backend << "): " << e.what();
  72. }
  73. cout << name << " - PLUGIN (ERROR on quering information)" << endl;
  74. }
  75. TEST(VideoIO_Plugins, query)
  76. {
  77. const std::vector<cv::VideoCaptureAPIs> camera_backends = cv::videoio_registry::getCameraBackends();
  78. cout << "== Camera APIs (" << camera_backends.size() << "):" << endl;
  79. for (auto backend : camera_backends)
  80. {
  81. dumpBackendInfo(backend, MODE_CAMERA);
  82. }
  83. const std::vector<cv::VideoCaptureAPIs> stream_backends = cv::videoio_registry::getStreamBackends();
  84. cout << "== Stream capture APIs (" << stream_backends.size() << "):" << endl;
  85. for (auto backend : stream_backends)
  86. {
  87. dumpBackendInfo(backend, MODE_STREAM);
  88. }
  89. const std::vector<cv::VideoCaptureAPIs> writer_backends = cv::videoio_registry::getWriterBackends();
  90. cout << "== Writer APIs (" << writer_backends.size() << "):" << endl;
  91. for (auto backend : writer_backends)
  92. {
  93. dumpBackendInfo(backend, MODE_WRITER);
  94. }
  95. }
  96. }}