Skip to content

Commit b4e941d

Browse files
committed
VideoCapture test to ensure that cv::VideoCapture does not share output buffers between frames.
1 parent 7a790d0 commit b4e941d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

modules/videoio/test/test_video_io.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,37 @@ static vector<Ext_Fourcc_API> generate_Ext_Fourcc_API_nocrash()
616616

617617
INSTANTIATE_TEST_CASE_P(videoio, Videoio_Writer_bad_fourcc, testing::ValuesIn(generate_Ext_Fourcc_API_nocrash()));
618618

619+
typedef testing::TestWithParam<VideoCaptureAPIs> safe_capture;
620+
621+
TEST_P(safe_capture, frames_independency)
622+
{
623+
VideoCaptureAPIs apiPref = GetParam();
624+
if (!videoio_registry::hasBackend(apiPref))
625+
throw SkipTestException(cv::String("Backend is not available/disabled: ") + cv::videoio_registry::getBackendName(apiPref));
626+
627+
VideoCapture cap;
628+
String video_file = BunnyParameters::getFilename(String(".avi"));
629+
EXPECT_NO_THROW(cap.open(video_file, apiPref));
630+
if (!cap.isOpened())
631+
{
632+
std::cout << "SKIP test: backend " << apiPref << " can't open the video: " << video_file << std::endl;
633+
return;
634+
}
635+
636+
Mat frames[10];
637+
Mat hardCopies[10];
638+
for(int i = 0; i < 10; i++)
639+
{
640+
ASSERT_NO_THROW(cap >> frames[i]);
641+
EXPECT_FALSE(frames[i].empty());
642+
hardCopies[i] = frames[i].clone();
643+
}
644+
645+
for(int i = 0; i < 10; i++)
646+
EXPECT_EQ(0, cv::norm(frames[i], hardCopies[i], NORM_INF)) << i;
647+
}
648+
649+
static VideoCaptureAPIs safe_apis[] = {CAP_FFMPEG, CAP_GSTREAMER, CAP_MSMF,CAP_AVFOUNDATION};
650+
INSTANTIATE_TEST_CASE_P(videoio, safe_capture, testing::ValuesIn(safe_apis));
651+
619652
} // namespace

0 commit comments

Comments
 (0)