Picamera2 Python camera library for Raspberry Pi leverages libcamera open-source framework

Raspberry Pi Trading released a new version of Raspberry Pi OS last week with the highlight being the Picamera2 Python library for Raspberry Pi cameras, along with small changes such as the ability to search menu items, a new audio input control,

The new Picamera2 library was first announced in mid February 2022 with a preview release, and it’s the first time the Python library is included by default in Raspberry Pi OS. It is now based on the libcamera open-source framework instead of the proprietary and closed camera APIs from Broadcom found in the original Picamera library.

Qt Picamera2 App
Qt Picamera2 App

Some of the key features of the Picamera2 library include:

  • The preview windows use OpenGL acceleration for hardware-assisted rendering or DRM/KMS for efficient rendering when X Windows is not running
  • Picamera2 commands can be typed into a Python interpreter or scripts
  • Support for embedding Picamera2 widgets into Qt applications
  • NumPy integration provides easier use of OpenCV, TensorFlow, and other Python “scientific computing” libraries.
  • Video encoding and recording
  • Record audio and video together
  • Drawing display overlays on top of the camera images
  • All official Raspberry Pi cameras are supported as well as some third-party cameras from Arducam and others.
Picamera2 Tensorflow
Picamera2 TensorFlow example: dog detection and segmentation

The source code and documentation (65-page PDF file) can be found on GitHub. The library should be installed in the latest Raspberry Pi OS image, but if somehow it’s not there, or you’d like to install it on an older Bullseye image, it can be installed as follows:


Capturing an image is just the lines of code:


If you want to show a preview window before the capture, it’s not overly complicated either.


The sample code above is valid with X-Windows, but if you’re not using X-Windows, Preview.QTGL by Preview.DRM instead:


You can also capture videos, adjust camera parameters (exposure, gain, etc..), display overlays, stream video to the network, and more.

Future plans include fixing bugs that may show up in the beta version, working on better documentation, improving the frame-by-frame control of exposure and gain, etc…

Via Raspberry Pi website

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX RK3588 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
0 Comments
oldest
newest
Khadas VIM4 SBC