From b4e941d43113ecad33bea3f8fd7a1f14771c7077 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 21 Jan 2021 11:57:45 +0300 Subject: [PATCH] VideoCapture test to ensure that cv::VideoCapture does not share output buffers between frames. --- modules/videoio/test/test_video_io.cpp | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/modules/videoio/test/test_video_io.cpp b/modules/videoio/test/test_video_io.cpp index f6b23a3dd9..ff2a4442dd 100644 --- a/modules/videoio/test/test_video_io.cpp +++ b/modules/videoio/test/test_video_io.cpp @@ -616,4 +616,37 @@ static vector generate_Ext_Fourcc_API_nocrash() INSTANTIATE_TEST_CASE_P(videoio, Videoio_Writer_bad_fourcc, testing::ValuesIn(generate_Ext_Fourcc_API_nocrash())); +typedef testing::TestWithParam safe_capture; + +TEST_P(safe_capture, frames_independency) +{ + VideoCaptureAPIs apiPref = GetParam(); + if (!videoio_registry::hasBackend(apiPref)) + throw SkipTestException(cv::String("Backend is not available/disabled: ") + cv::videoio_registry::getBackendName(apiPref)); + + VideoCapture cap; + String video_file = BunnyParameters::getFilename(String(".avi")); + EXPECT_NO_THROW(cap.open(video_file, apiPref)); + if (!cap.isOpened()) + { + std::cout << "SKIP test: backend " << apiPref << " can't open the video: " << video_file << std::endl; + return; + } + + Mat frames[10]; + Mat hardCopies[10]; + for(int i = 0; i < 10; i++) + { + ASSERT_NO_THROW(cap >> frames[i]); + EXPECT_FALSE(frames[i].empty()); + hardCopies[i] = frames[i].clone(); + } + + for(int i = 0; i < 10; i++) + EXPECT_EQ(0, cv::norm(frames[i], hardCopies[i], NORM_INF)) << i; +} + +static VideoCaptureAPIs safe_apis[] = {CAP_FFMPEG, CAP_GSTREAMER, CAP_MSMF,CAP_AVFOUNDATION}; +INSTANTIATE_TEST_CASE_P(videoio, safe_capture, testing::ValuesIn(safe_apis)); + } // namespace