perf_camera.impl.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // Not a standalone header.
  5. #include <opencv2/core/utils/configuration.private.hpp>
  6. namespace opencv_test {
  7. using namespace perf;
  8. static
  9. utils::Paths getTestCameras()
  10. {
  11. static utils::Paths cameras = utils::getConfigurationParameterPaths("OPENCV_TEST_PERF_CAMERA_LIST");
  12. return cameras;
  13. }
  14. PERF_TEST(VideoCapture_Camera, waitAny_V4L)
  15. {
  16. auto cameraNames = getTestCameras();
  17. if (cameraNames.empty())
  18. throw SkipTestException("No list of tested cameras. Use OPENCV_TEST_PERF_CAMERA_LIST parameter");
  19. const int totalFrames = 50; // number of expected frames (summary for all cameras)
  20. const int64 timeoutNS = 100 * 1000000;
  21. const Size frameSize(640, 480);
  22. const int fpsDefaultEven = 30;
  23. const int fpsDefaultOdd = 15;
  24. std::vector<VideoCapture> cameras;
  25. for (size_t i = 0; i < cameraNames.size(); ++i)
  26. {
  27. const auto& name = cameraNames[i];
  28. int fps = (int)utils::getConfigurationParameterSizeT(cv::format("OPENCV_TEST_CAMERA%d_FPS", (int)i).c_str(), (i & 1) ? fpsDefaultOdd : fpsDefaultEven);
  29. std::cout << "Camera[" << i << "] = '" << name << "', fps=" << fps << std::endl;
  30. VideoCapture cap(name, CAP_V4L);
  31. ASSERT_TRUE(cap.isOpened()) << name;
  32. EXPECT_TRUE(cap.set(CAP_PROP_FRAME_WIDTH, frameSize.width)) << name;
  33. EXPECT_TRUE(cap.set(CAP_PROP_FRAME_HEIGHT, frameSize.height)) << name;
  34. EXPECT_TRUE(cap.set(CAP_PROP_FPS, fps)) << name;
  35. //launch cameras
  36. Mat firstFrame;
  37. EXPECT_TRUE(cap.read(firstFrame));
  38. EXPECT_EQ(frameSize.width, firstFrame.cols);
  39. EXPECT_EQ(frameSize.height, firstFrame.rows);
  40. cameras.push_back(cap);
  41. }
  42. TEST_CYCLE()
  43. {
  44. int counter = 0;
  45. std::vector<int> cameraReady;
  46. do
  47. {
  48. EXPECT_TRUE(VideoCapture::waitAny(cameras, cameraReady, timeoutNS));
  49. EXPECT_FALSE(cameraReady.empty());
  50. for (int idx : cameraReady)
  51. {
  52. VideoCapture& c = cameras[idx];
  53. Mat frame;
  54. ASSERT_TRUE(c.retrieve(frame));
  55. EXPECT_EQ(frameSize.width, frame.cols);
  56. EXPECT_EQ(frameSize.height, frame.rows);
  57. ++counter;
  58. }
  59. }
  60. while(counter < totalFrames);
  61. }
  62. SANITY_CHECK_NOTHING();
  63. }
  64. } // namespace