Empowering Raspberry Pi Camera with Picamera2: Unlocking the World of Imaging

As a powerful microcomputer, Raspberry Pi’s strong image processing capabilities attract numerous makers and developers. In the past, Picamera, as the official Python imaging library for Raspberry Pi, provided developers with a convenient way to capture and process images. However, with the continuous development of technology, Picamera can no longer meet new demands. Therefore, the Raspberry Pi Foundation has launched a brand new camera library Picamera2, which is based on the libcamera architecture, providing more powerful features, higher performance, and an easier-to-use API, becoming a new tool for Raspberry Pi camera application development.

Empowering Raspberry Pi Camera with Picamera2: Unlocking the World of Imaging

Advantages of Picamera2

Compared to Picamera, Picamera2 has many advantages:

1. Based on libcamera: libcamera is a modern camera framework that offers more efficient resource management, supports a wider range of camera functions, and is compatible with various camera hardware. Picamera2 fully utilizes the advantages of libcamera to bring developers more powerful features and more stable performance.

2. Easy-to-use Python API: Picamera2 provides a simple and understandable Python API, allowing developers to easily configure cameras, capture images, and process images. Its concise design enables developers to quickly get started and focus more on application development itself.

Empowering Raspberry Pi Camera with Picamera2: Unlocking the World of Imaging

3. Rich features: Picamera2 supports various camera functions, such as:

  • • High-resolution image capture

  • • Video recording

  • • RAW format image capture

  • • Multi-camera support

  • • Real-time image processing

  • • Hardware acceleration

4. Cross-platform support: In addition to supporting Raspberry Pi, Picamera2 also supports other Linux platforms, such as Ubuntu and Debian, allowing developers to port applications to other platforms.

Installation and Usage

1. System Requirements:

Picamera2 only supports Raspberry Pi OS Bullseye (or higher versions), including both 32-bit and 64-bit versions. Since September 2022, Picamera2 has been pre-installed in images downloaded from Raspberry Pi. It is compatible with all Raspberry Pi boards, including Pi Zero, but performance may vary due to differences in device performance.

Picamera2 does not support:

  • • Systems based on Buster or earlier version images.

  • • Raspberry Pi OS Legacy images.

  • • Bullseye (or higher version) images that have re-enabled the legacy camera stack.

2. Installation Methods:

Install using apt:

It is recommended to install Picamera2 using apt.

  • Update Picamera2: If Picamera2 is already installed, you can update it using sudo apt install -y python3-picamera2 or as part of a system update (e.g., sudo apt upgrade).

  • Install Picamera2: If Picamera2 is not yet installed, you can update the software source using sudo apt update, and then update the system using sudo apt upgrade. If Picamera2 was previously installed using pip, you need to uninstall it first using pip3 uninstall picamera2.

  • Install Picamera2 (including GUI dependencies): sudo apt install -y python3-picamera2

  • Install Picamera2 (excluding GUI dependencies): sudo apt install -y python3-picamera2 --no-install-recommends

Install using pip:

  • • Use sudo apt install -y python3-libcamera python3-kms++ to install libcamera and KMS++.

  • • Use sudo apt install -y python3-pyqt5 python3-prctl libatlas-base-dev ffmpeg python3-pip to install PyQt5, prctl, libatlas-base-dev, ffmpeg, and pip.

  • • Use pip3 install numpy --upgrade to upgrade numpy.

  • • Use pip3 install picamera2[gui] to install Picamera2 (including GUI dependencies).

  • • Use pip3 install picamera2 to install Picamera2 (excluding GUI dependencies).

3. Getting Started:

Picamera2 provides rich example code to help developers get started quickly. Example code is located in the examples directory of the project repository, and there are also Qt application example codes in the apps directory.

Conclusion

Picamera2 is a powerful and easy-to-use camera library that can help developers fully leverage the image processing capabilities of Raspberry Pi. Whether you are an experienced developer or a beginner, Picamera2 is your best choice for Raspberry Pi camera application development.

Project Address: https://github.com/raspberrypi/picamera2

Leave a Comment

×