From d0de575aef0b3383f183f6951a64dddc02a7563a Mon Sep 17 00:00:00 2001 From: beanjoy <120680451@qq.com> Date: Thu, 7 Sep 2023 18:06:39 +0800 Subject: [PATCH] Merge pull request #24142 from beanjoy:4.x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modify the outputVideoFormat after changing the output format in MSMF backend #24142 After changing the output format, need to modify the outputVideoFormat, otherwise the outputVideoFormat is always CV_CAP_MODE_BGR, and an error will occur when converting the format in retrieveVideoFrame(), and will always enter "case CV_CAP_MODE_BGR:" process. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [ ] I agree to contribute to the project under Apache 2 License. - [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake Co-authored-by: 李龙 --- modules/videoio/src/cap_msmf.cpp | 7 ++++++- modules/videoio/test/test_camera.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/videoio/src/cap_msmf.cpp b/modules/videoio/src/cap_msmf.cpp index a55f919ed1..4b234b8cae 100644 --- a/modules/videoio/src/cap_msmf.cpp +++ b/modules/videoio/src/cap_msmf.cpp @@ -1159,7 +1159,12 @@ bool CvCapture_MSMF::configureVideoOutput(MediaType newType, cv::uint32_t outFor { initStream(dwVideoStreamIndex, nativeFormat); } - return initStream(dwVideoStreamIndex, newFormat); + if (!initStream(dwVideoStreamIndex, newFormat)) + { + return false; + } + outputVideoFormat = outFormat; + return true; } bool CvCapture_MSMF::configureOutput() diff --git a/modules/videoio/test/test_camera.cpp b/modules/videoio/test/test_camera.cpp index fc269959c3..8b0f0efe83 100644 --- a/modules/videoio/test/test_camera.cpp +++ b/modules/videoio/test/test_camera.cpp @@ -119,6 +119,21 @@ TEST(DISABLED_videoio_camera, v4l_read_mjpg) capture.release(); } +TEST(DISABLED_videoio_camera, msmf_read_yuyv) +{ + VideoCapture capture(CAP_MSMF); + ASSERT_TRUE(capture.isOpened()); + ASSERT_TRUE(capture.set(CAP_PROP_FOURCC, VideoWriter::fourcc('Y', 'U', 'Y', 'V'))); + std::cout << "Camera 0 via " << capture.getBackendName() << " backend" << std::endl; + std::cout << "Frame width: " << capture.get(CAP_PROP_FRAME_WIDTH) << std::endl; + std::cout << " height: " << capture.get(CAP_PROP_FRAME_HEIGHT) << std::endl; + std::cout << "Capturing FPS: " << capture.get(CAP_PROP_FPS) << std::endl; + int fourcc = (int)capture.get(CAP_PROP_FOURCC); + std::cout << "FOURCC code: " << cv::format("0x%8x", fourcc) << std::endl; + test_readFrames(capture); + capture.release(); +} + TEST(DISABLED_videoio_camera, v4l_open_mjpg) { VideoCapture capture;