mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge pull request #15100 from Volskig:cam_multiplexing_function_v
Implement Camera Multiplexing API * IdideoCapture + two wrong function function waitAny Add errors catcher Stub for Python added. Sifting warnings One test added Two tests for camera and Perf tests added * Perf sync and async tests for waitAny() added, waitAnyInterior() deleted, getDeviceHandle() deleted * Variable OPENCV_TEST_CAMERA_LIST added * Without fps set * ASSERT_FAILED for environment variable * Perf tests is DISABLED_ * --Trailing whitespace * Return false from cap.cpp deleted * Two functions deleted from interface, +range for, +environment variable in test_camera * Space deleted * printf deleted, perror added * CV_WRAP deleted, cv2 cleared from stubs * -- space * default timeout added * @param changed * place of waitAny changed * --whitespace * ++function description * function description changed * revert unused changes * videoio: rework API for VideoCapture::waitAny()
This commit is contained in:
committed by
Alexander Alekhin
parent
ac2dc29525
commit
1acadd363b
@@ -8,6 +8,7 @@
|
||||
// Usage: opencv_test_videoio --gtest_also_run_disabled_tests --gtest_filter=*videoio_camera*<tested case>*
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include <opencv2/core/utils/configuration.private.hpp>
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
|
||||
@@ -105,4 +106,79 @@ TEST(DISABLED_videoio_camera, v4l_read_framesize)
|
||||
capture.release();
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
utils::Paths getTestCameras()
|
||||
{
|
||||
static utils::Paths cameras = utils::getConfigurationParameterPaths("OPENCV_TEST_CAMERA_LIST");
|
||||
return cameras;
|
||||
}
|
||||
|
||||
TEST(DISABLED_videoio_camera, waitAny_V4L)
|
||||
{
|
||||
auto cameraNames = getTestCameras();
|
||||
if (cameraNames.empty())
|
||||
throw SkipTestException("No list of tested cameras. Use OPENCV_TEST_CAMERA_LIST parameter");
|
||||
|
||||
const int totalFrames = 50; // number of expected frames (summary for all cameras)
|
||||
const int64 timeoutNS = 100 * 1000000;
|
||||
|
||||
const Size frameSize(640, 480);
|
||||
const int fpsDefaultEven = 30;
|
||||
const int fpsDefaultOdd = 15;
|
||||
|
||||
std::vector<VideoCapture> cameras;
|
||||
for (size_t i = 0; i < cameraNames.size(); ++i)
|
||||
{
|
||||
const auto& name = cameraNames[i];
|
||||
int fps = (int)utils::getConfigurationParameterSizeT(cv::format("OPENCV_TEST_CAMERA%d_FPS", (int)i).c_str(), (i & 1) ? fpsDefaultOdd : fpsDefaultEven);
|
||||
std::cout << "Camera[" << i << "] = '" << name << "', fps=" << fps << std::endl;
|
||||
VideoCapture cap(name, CAP_V4L);
|
||||
ASSERT_TRUE(cap.isOpened()) << name;
|
||||
EXPECT_TRUE(cap.set(CAP_PROP_FRAME_WIDTH, frameSize.width)) << name;
|
||||
EXPECT_TRUE(cap.set(CAP_PROP_FRAME_HEIGHT, frameSize.height)) << name;
|
||||
EXPECT_TRUE(cap.set(CAP_PROP_FPS, fps)) << name;
|
||||
//launch cameras
|
||||
Mat firstFrame;
|
||||
EXPECT_TRUE(cap.read(firstFrame));
|
||||
EXPECT_EQ(frameSize.width, firstFrame.cols);
|
||||
EXPECT_EQ(frameSize.height, firstFrame.rows);
|
||||
cameras.push_back(cap);
|
||||
}
|
||||
|
||||
std::vector<size_t> frameFromCamera(cameraNames.size(), 0);
|
||||
{
|
||||
int counter = 0;
|
||||
std::vector<int> cameraReady;
|
||||
do
|
||||
{
|
||||
EXPECT_TRUE(VideoCapture::waitAny(cameras, cameraReady, timeoutNS));
|
||||
EXPECT_FALSE(cameraReady.empty());
|
||||
for (int idx : cameraReady)
|
||||
{
|
||||
//std::cout << "Reading frame from camera: " << idx << std::endl;
|
||||
ASSERT_TRUE(idx >= 0 && (size_t)idx < cameras.size()) << idx;
|
||||
VideoCapture& c = cameras[idx];
|
||||
Mat frame;
|
||||
#if 1
|
||||
ASSERT_TRUE(c.retrieve(frame)) << idx;
|
||||
#else
|
||||
ASSERT_TRUE(c.read(frame)) << idx;
|
||||
#endif
|
||||
EXPECT_EQ(frameSize.width, frame.cols) << idx;
|
||||
EXPECT_EQ(frameSize.height, frame.rows) << idx;
|
||||
|
||||
++frameFromCamera[idx];
|
||||
++counter;
|
||||
}
|
||||
}
|
||||
while(counter < totalFrames);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < cameraNames.size(); ++i)
|
||||
{
|
||||
EXPECT_GT(frameFromCamera[i], (size_t)0) << i;
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user