To use this guide, you will need to install picamzero - a library designed to make using the camera on the Raspberry Pi as easy as possible.

Learn how to connect the Raspberry Pi Camera Module to your Raspberry Pi and take pictures, record video, and apply image effects.

Troubleshooting

  • Check the status of the camera on a Raspberry Pi when the legacy camera stack is enabled
sudo vcgencmd get_camera
supported=1 detected=1, libcamera interfaces=0 # legacy disabled
  • Check for libcamera device permissions
ls /dev/video*
  • Disable Legacy Camera and I2C: raspi-config Interface options
sudo raspi-config
  • Test OpenGL with a simple application
glxgears

Build libcamera and rpicam-apps

rpicam-apps

https://www.raspberrypi.com/documentation/computers/camera_software.html#rpicam-apps

libcamera

Libcamera is a camera stack designed to provide camera control for Linux-based systems, including the Raspberry Pi. It is used as the foundation for the Raspberry Pi camera driver in recent versions of Raspberry Pi OS. This stack provides lower-level access to the camera and includes features like video capture, still image capture, and camera sensor configuration.

While libcamera is mainly a C++ library, the Python bindings for libcamera (accessible via python3-libcamera) allow you to interface with the camera from Python scripts. However, these bindings are still evolving and do not provide the same level of abstraction or ease of use as picamera2.

rpicam-hello

rpicam-hello --timeout 0

rpicam-jpeg

  • Capture an image
rpicam-jpeg --output test.jpg

Install libcamera nad rpicam-apps from source

Build libcamera

https://github.com/raspberrypi/picamera2/issues/563#issuecomment-1981658308

  • Install libcamera dependencies
sudo apt install -y libcamera-dev libepoxy-dev libjpeg-dev libtiff5-dev libpng-dev python3 python3-dev
sudo apt install libcamera-tools g++
sudo apt install -y python3-pip git python3-jinja2
sudo apt install -y libboost-dev
sudo apt install -y libgnutls28-dev openssl libtiff5-dev pybind11-dev liblttng-ust-dev
sudo apt install -y qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5
# NOTE - for Ubuntu 22.04, need to install meson via pip because the version apt gets is too old
sudo apt install -y cmake ninja-build 
sudo apt install -y python3-yaml python3-ply python3-pip libyaml-dev
  • Install meson
sudo pip3 install meson
sudo find /root/.local -name meson
# /root/.local/bin/meson
sudo ln -s /root/.local/bin/meson /usr/local/bin/meson
sudo meson --version
# 1.6.1
  • Download the repo
cd 
git clone https://github.com/raspberrypi/libcamera.git
cd libcamera
  • Run meson to configure the build environment
sudo meson setup build --buildtype=release -Dpipelines=rpi/vc4,rpi/pisp -Dipas=rpi/vc4,rpi/pisp -Dv4l2=true -Dgstreamer=enabled -Dtest=false -Dlc-compliance=disabled -Dcam=disabled -Dqcam=disabled -Ddocumentation=disabled -Dpycamera=enabled
  • Build libcamera with ninja
sudo ninja -C build -j 2   # use -j 2 on Raspberry Pi 3 or earlier devices
  • Install libcamera
sudo ninja -C build install

Build rpicam-apps

  • Fetch dependencies
sudo apt install -y libboost-program-options-dev libdrm-dev libexif-dev
  • clone repo
cd 
git clone https://github.com/raspberrypi/rpicam-apps.git --branch v1.4.3
cd rpicam-apps
  • Configure the rpicam-apps build with the following meson command
sudo meson setup build -Denable_libav=false -Denable_drm=true -Denable_egl=false -Denable_qt=false -Denable_opencv=false -Denable_tflite=false
  • Build rpicam-apps
sudo meson compile -C build -j1 # use -j1 on Raspberry Pi 3 or earlier devices
  • Install rpicam-apps
sudo /home/$USER/.local/bin/meson install -C build
  • Udpate the ldconfig cache
sudo ldconfig # this is only necessary on the first build
  • Check that your device uses the new binary
rpicam-still --version

Picamera

Picamera2 is the libcamera-based replacement for Picamera which was a Python interface to the Raspberry Pi’s legacy camera stack. Picamera2 also presents an easy to use Python API.

Install picamera2 on Ubuntu 22.04

https://github.com/raspberrypi/picamera2/issues/563#issuecomment-1981658308

  • Install libkms dependencies
sudo apt update && sudo apt upgrade
sudo apt install -y  libfmt-dev libdrm-dev libfmt-dev
# Install kmsxx
git clone https://github.com/tomba/kmsxx.git
cd kmsxx/
git submodule update --init
sudo meson build -Dpykms=enabled
sudo ninja -C build install
apt install libcap-dev
  • Install rpi-kms
    • Note: “The pip installation of rpi-libcamera and rpi-kms may take a while (>3mins on pi4) on the “Preparing metadata (pyproject.toml)” stage, as it is compiling the python bindings from scratch”
sudo pip install rpi-kms 
sudo pip install rpi-libcamera 
  • Install picamera
sudo pip install picamera2
  • Test picamera2 installation
from picamera2 import Picamera2
 
picam2 = Picamera2()
 
picam2.start_and_capture_file("test.jpg", show_preview=False)