mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge pull request #18535 from joshdoe:gray16_gstreamer_writing
Add CV_16UC1/GRAY16_LE support to GStreamer backend for VideoWriter * videoio(backend): add Writer_open_with_params to plugin API This will allow arbitrary parameters to be passed to plugin backends * videoio(gstreamer): add GRAY16_LE/CV_16UC1 writing support to GStreamer This introduces a new property VIDEOWRITER_PROP_DEPTH, which defaults to CV_8U, but for GStreamer can be set to CV_16U. Also, fix another test to not fail if plugin isn't found, copying logic from the read_write test. * videoio(plugin): fix handling plugins with previous API level * videoio: coding style * fix warning
This commit is contained in:
@@ -73,22 +73,63 @@ Param test_data[] = {
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(videoio, videoio_gstreamer, testing::ValuesIn(test_data));
|
||||
|
||||
TEST(Videoio_GStreamer, unsupported_pipeline)
|
||||
TEST(videoio_gstreamer, unsupported_pipeline)
|
||||
{
|
||||
VideoCaptureAPIs apiPref = CAP_GSTREAMER;
|
||||
if (!isBackendAvailable(apiPref, cv::videoio_registry::getStreamBackends()))
|
||||
throw SkipTestException(cv::String("Backend is not available/disabled: ") + cv::videoio_registry::getBackendName(apiPref));
|
||||
if (!videoio_registry::hasBackend(CAP_GSTREAMER))
|
||||
throw SkipTestException("GStreamer backend was not found");
|
||||
|
||||
// could not link videoconvert0 to matroskamux0, matroskamux0 can't handle caps video/x-raw, format=(string)RGBA
|
||||
std::string pipeline = "appsrc ! videoconvert ! video/x-raw, format=(string)RGBA ! matroskamux ! filesink location=test.mkv";
|
||||
Size frame_size(640, 480);
|
||||
|
||||
VideoWriter writer;
|
||||
EXPECT_NO_THROW(writer.open(pipeline, apiPref, 0/*fourcc*/, 30/*fps*/, frame_size, true));
|
||||
EXPECT_NO_THROW(writer.open(pipeline, CAP_GSTREAMER, 0/*fourcc*/, 30/*fps*/, frame_size, true));
|
||||
EXPECT_FALSE(writer.isOpened());
|
||||
// no frames
|
||||
EXPECT_NO_THROW(writer.release());
|
||||
|
||||
}
|
||||
|
||||
TEST(videoio_gstreamer, gray16_writing)
|
||||
{
|
||||
if (!videoio_registry::hasBackend(CAP_GSTREAMER))
|
||||
throw SkipTestException("GStreamer backend was not found");
|
||||
|
||||
Size frame_size(320, 240);
|
||||
|
||||
// generate a noise frame
|
||||
Mat frame = Mat(frame_size, CV_16U);
|
||||
randu(frame, 0, 65535);
|
||||
|
||||
// generate a temp filename, and fix path separators to how GStreamer expects them
|
||||
cv::String temp_file = cv::tempfile(".raw");
|
||||
std::replace(temp_file.begin(), temp_file.end(), '\\', '/');
|
||||
|
||||
// write noise frame to file using GStreamer
|
||||
std::ostringstream writer_pipeline;
|
||||
writer_pipeline << "appsrc ! filesink location=" << temp_file;
|
||||
std::vector<int> params {
|
||||
VIDEOWRITER_PROP_IS_COLOR, 0/*false*/,
|
||||
VIDEOWRITER_PROP_DEPTH, CV_16U
|
||||
};
|
||||
VideoWriter writer;
|
||||
ASSERT_NO_THROW(writer.open(writer_pipeline.str(), CAP_GSTREAMER, 0/*fourcc*/, 30/*fps*/, frame_size, params));
|
||||
ASSERT_TRUE(writer.isOpened());
|
||||
ASSERT_NO_THROW(writer.write(frame));
|
||||
ASSERT_NO_THROW(writer.release());
|
||||
|
||||
// read noise frame back in
|
||||
Mat written_frame(frame_size, CV_16U);
|
||||
std::ifstream fs(temp_file, std::ios::in | std::ios::binary);
|
||||
fs.read((char*)written_frame.ptr(0), frame_size.width * frame_size.height * 2);
|
||||
ASSERT_TRUE(fs);
|
||||
fs.close();
|
||||
|
||||
// compare to make sure it's identical
|
||||
EXPECT_EQ(0, cv::norm(frame, written_frame, NORM_INF));
|
||||
|
||||
// remove temp file
|
||||
EXPECT_EQ(0, remove(temp_file.c_str()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user