Skip to content

modules/videoio: add libcamera backend for OpenCV VideoCapture #27254

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

Open
wants to merge 6 commits into
base: 4.x
Choose a base branch
from

Conversation

ssxc16
Copy link

@ssxc16 ssxc16 commented Apr 24, 2025

Feature: Add Libcamera backend

Summary:

This pull request introduces a new backend for the cv::VideoCapture module, providing support for cameras using the Libcamera library on Linux (and potentially other supported platforms).

You can find the complete implementation here.
Detailed usage instructions and sample testing program can be found here.

Motivation / Reason for this change:

Libcamera is the modern standard API for camera control on many recent Linux systems, including popular development boards like the Raspberry Pi. It offers a more robust and feature-rich interface compared to the legacy V4L2 API for many newer camera modules. Adding official Libcamera support to OpenCV will allow users on these platforms to fully utilize their cameras with cv::VideoCapture, replacing or complementing the existing V4L2 backend where applicable.

Implementation Details:

  • A new backend implementation cap_libcamera.cpp has been added to the modules/videoio/src/ directory.
  • The new backend registers itself under the API ID cv::VideoCaptureAPIs::CAP_LIBCAMERA.
  • The implementation utilizes the Libcamera C++ API to enumerate cameras, configure streams, capture frames, and set/get basic properties.
  • Reference to LCCV: The design and implementation concepts are significantly inspired by and borrow structure from the excellent LCCV project.

Implemented Features:

  • grabFrame, retrieveFrame for frame capture.
  • Setting and getting basic frame properties (width, height, frame rate - CAP_PROP_FRAME_WIDTH, CAP_PROP_FRAME_HEIGHT, CAP_PROP_FPS eg).
  • Multithreaded Frame Reading and Writing

Issues of multi-cameras

  • multiple USB cameras (can recognize and read)
  • one USB camera and one MIPI camera (index 0 will be the first recognized camera)
  • multiple MIPI cameras (can recognized but only index 0 can read)[WIP]

@asmorkalov
Copy link
Contributor

The branch works for me with Pi 4 and camera module v 2.1, but very slow. Looking on performance details.

@QueenofUSSR
Copy link

QueenofUSSR commented Apr 29, 2025

The branch works for me with Pi 4 and camera module v 2.1, but very slow. Looking on performance details.

Is the framerate too low or startup time too long? This branch has only been tested on Pi 5 and we didn't encounter that problem.

@QueenofUSSR
Copy link

QueenofUSSR commented May 8, 2025

The branch works for me with Pi 4 and camera module v 2.1, but very slow. Looking on performance details.

I have only reproduced part of this problem:

The full-screen framerate (not only imshow() window) could drop low when moving mouse cursor, and USB camera seems to have the same issue on Pi 4. The video framerate is normal except for this situation.

I'm trying to figure it out, detailed test code would be highly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy