mirror of
https://github.com/opencv/opencv.git
synced 2026-01-18 17:21:42 +01:00
47a64192909cf153e40ba094588e1a531d46f465
fix: set default pixel format for Aravis cameras when unsupported format #28086 Fixes #26523 This PR fixes an issue where Aravis VideoCapture returns empty frames when the camera's pixel format is not explicitly set via CAP_PROP_FOURCC. Problem: The Aravis backend's retrieveFrame() function only processes four specific pixel formats: - ARV_PIXEL_FORMAT_MONO_8 - ARV_PIXEL_FORMAT_BAYER_GR_8 - ARV_PIXEL_FORMAT_MONO_12 - ARV_PIXEL_FORMAT_MONO_16 If the camera has a different pixel format configured (or the camera's default format is unsupported), retrieveFrame() returns false on line 333 and all frames appear empty. This happens even though: - The camera opens successfully (isOpened() returns true) - The camera is capturing data - The user has set up autotrigger and auto-exposure correctly Root Cause: In open() at line 271, the code retrieves the camera's current pixel format with arv_camera_get_pixel_format(). But if this format doesn't match one of the four supported formats, there's no fallback, causing all subsequent frames to fail retrieval. Solution: Added a check after retrieving the camera's pixel format. If the format is not one of the four supported formats, the code now: 1. Sets pixelFormat to a sensible default (MONO_8) 2. Applies this format to the camera via arv_camera_set_pixel_format() This ensures: - Cameras work out-of-the-box without requiring explicit CAP_PROP_FOURCC setup - Users can still override the format with CAP_PROP_FOURCC if needed - Behavior matches user expectations from other camera backends (V4L2, MSMF, etc.) The default of MONO_8 was chosen because it's the most universally supported format across USB3 Vision and GigE Vision cameras. Changes: modules/videoio/src/cap_aravis.cpp: Added pixel format validation and default setting (10 lines) Testing: With this fix: - Cameras with unsupported default formats will automatically switch to MONO_8 - The sample code from the issue works without uncommenting the CAP_PROP_FOURCC line - Users can still explicitly set their preferred format via CAP_PROP_FOURCC Pull Request Readiness Checklist: - [x] I agree to contribute to the project under Apache 2 License. - [x] 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 - [x] The PR is proposed to the proper branch (4.x) - [x] There is a reference to the original bug report and related work (issue #26523) - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable N/A - This requires specialized USB3 Vision / GigE Vision hardware not available in CI - [x] The feature is well documented and sample code can be built with the project CMake The fix maintains existing API behavior and makes the backend work as expected
OpenCV: Open Source Computer Vision Library
Resources
- Homepage: https://opencv.org
- Courses: https://opencv.org/courses
- Docs: https://docs.opencv.org/4.x/
- Q&A forum: https://forum.opencv.org
- previous forum (read only): http://answers.opencv.org
- Issue tracking: https://github.com/opencv/opencv/issues
- Additional OpenCV functionality: https://github.com/opencv/opencv_contrib
- Donate to OpenCV: https://opencv.org/support/
Contributing
Please read the contribution guidelines before starting work on a pull request.
Summary of the guidelines:
- One pull request per issue;
- Choose the right base branch;
- Include tests and documentation;
- Clean up "oops" commits before submitting;
- Follow the coding style guide.
Additional Resources
- Submit your OpenCV-based project for inclusion in Community Friday on opencv.org
- Subscribe to the OpenCV YouTube Channel featuring OpenCV Live, an hour-long streaming show
- Follow OpenCV on LinkedIn for daily posts showing the state-of-the-art in computer vision & AI
- Apply to be an OpenCV Volunteer to help organize events and online campaigns as well as amplify them
- Follow OpenCV on Mastodon in the Fediverse
- Follow OpenCV on Twitter
- OpenCV.ai: Computer Vision and AI development services from the OpenCV team.
Description
Languages
C++
87.5%
C
3.1%
Python
3%
CMake
2%
Java
1.5%
Other
2.7%