-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
[WIP] modules/videoio: add libcamera backend for OpenCV Video I/O #27155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.x
Are you sure you want to change the base?
Conversation
Let's use FMT_BGR888 by default, if |
Raspberry Pi 4, libcamera from git default branch as in gist.
Build:
|
Similar issue with system wide (libcamera-dev) package:
|
int error; | ||
if (buffer->planes().empty()) | ||
{ | ||
std::cerr << "Buffer has no planes " << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use CV_LOG_XXX macro for reporting.
std::cerr << "plane is out of buffer: " | ||
<< "buffer length=" << length | ||
<< ", plane offset=" << plane.offset | ||
<< ", plane length=" << plane.length << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same for CV_LOG_XXX
Hmm, I'm not sure why you are facing this issue. Raspberry pi also ships with its custom fork of libcamera, could that be causing an issue? I have tested this on a Raspberry Pi 5 with a Picamera 2 and on my x84_64 Linux machine and it builds fine on both without any errors. |
Yes will do, I wasn't sure what to set as the default as many UVC cameras just sendsMJPEG and YUYV streams, so the BGR888 format crashes it. We will probably need to check the supported camera pixel formats and then update the default before configuring the stream. |
b3e9351
to
8be783f
Compare
Thank you for your excellent initiative and contribution in developing a libcamera backend for OpenCV! We have been closely following your work and are very impressed with your progress.
We have achieved a highly complete implementation with this architecture, and it demonstrates promising performance in our testing. However, we are currently addressing some bugs, particularly related to rapid release and restart scenarios, before we are fully confident in submitting a pull request. |
Thank you for your kind words and insights @Lookplanes. It's nice to hear that your team has made significant progress with your architecture, I'm looking forward to your approach. If you’re open to it, would you be willing to share your source code or repository? I would love to collaborate on developing a solution. |
Certainly! Please check opencv-RPiCamera |
Adds libcamera backend for OpenCV's Video I/O module. Provides integration with the libcamera stack, enabling native support for modern Linux camera pipelines, especially on embedded platforms like Raspberry Pi.
Implements the functionality to be used by the VideoCapture class for reading and displaying supported streams.
What works
cv::CAP_PROP_FRAME_WIDTH
– Set frame widthcv::CAP_PROP_FRAME_HEIGHT
– Set frame heightcv::CAP_PROP_MODE
– Select PixelFormat(e.g.,
FMT_MJPEG
,FMT_YUYV
,FMT_RGB888
,FMT_BGR888
,FMT_NV12
,FMT_YUV420
)cv::CAP_PROP_FORMAT
– Select StreamRole(e.g.,
ROLE_RAW
,ROLE_VIDEO
,ROLE_STILL
,ROLE_VIEWFINDER
)cv::CAP_PROP_FRAME_WIDTH
cv::CAP_PROP_FRAME_HEIGHT
Known issues
cv::CAP_PROP_MODE
must be explicitly set, for USB and CSI cameras, to avoid crashes.Detailed usage instructions can be found here.
Sample testing program can be found here.
Attempts to close #21653
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.