Google Summer of Code'23

Final blog of my project integrating libcamera into OpenCV

This is my Google Summer of Code 2023 project with libcamera.

It aims to move the current V4L2 implementation of accessing and controlling cameras in OpenCV to libcamera, this will allow for better functionality for more advanced and complex cameras. This will be done by creating a videoio plugin for OpenCV to support libcamera and then creating suitable classes and functions to add the desired functionality.

Project Details

Contributor Name: Advait Dhamorikar

Mentors: Umang Jain, Paul Elder

Organization: libcamera

Project: Integrating libcamera into OpenCV

Links:


Workflow Overview

OpenCV is a popular computer-vision library used that offers ease of usage, libcamera is a camera-stack that can handle the complexity of modern embedded cameras with support for open and closed source IPAs. The project aimed to integrate libcamera into the OpenCV backend.

Adding libcamera support

If you have libcamera installedhttps://libcamera.org/getting-started.html and use the libcamera backend when creating a VideoCapture object using

cv::VideoCapture cap(0,cv::CAP_LIBCAMERA)

and if you had used this flag when using CMake

-D WITH_LIBCAMERA=ON

macros have been setup which check if your installation is working, thus the

HAVE_LIBCAMERA

flag will be set to true.

OpenCV backend

The call to libcamera is made primarily by the cap_libcamera.cpp which handles all of the function calls, Where the Class CvCapture_libcamera_proxy is derived from OpenCVs IVideoCapture Class its member functions include:


Contributions

You can check my commits and code here, the branch is yet to be merged into upstream:

  1. Adding necessary libcamera addons to backend
  2. Implement open functionality
  3. Add buffer allocation capabilities
  4. Add all necessary IVideoCapture functions framework
  5. Add pixelformat and colour conversion capabilities
  6. Fix dependency issue and some bugs


Known issues

The backend has been integrated and supports majority of the IVideoCapture functions and the stream data is successfully being mmaped, however the format and colour conversion of this mapped data is still in testing for YUYV at the time of writing this blog.

Future Work


Acknowledgements

A very special thanks to my mentors Umang Jain(uajain), Paul Elder (epoll) for always answering my doubts and supporting me throughout. It was a great experience working with them and getting to learn so many new things as a part of the Google Summer of Code. I would also like to extend thanks to Laurent Pinchart(pinchartl), Kieran Bingham(kbingham) and other members of the libcamera organization who helped with my queries.

libcamera + GSoC = :-)