Merge pull request #24142 from beanjoy:4.x

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: 李龙 <lilong@sobey.com>
pull/24239/head
beanjoy 1 year ago committed by GitHub
parent 1ebea1e0f0
commit d0de575aef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      modules/videoio/src/cap_msmf.cpp
  2. 15
      modules/videoio/test/test_camera.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()

@ -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;

Loading…
Cancel
Save