• Stars
    star
    852
  • Rank 53,494 (Top 2 %)
  • Language
    Python
  • License
    BSD 2-Clause "Sim...
  • Created almost 3 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

New libcamera based python library

Picamera2


Picamera2 is currently available here as a beta release. This means there may still be some issues and bugs which we shall work on fixing, and where users identify particularly useful features we may still consider implementing them. Mostly we shall be working on bugs, stability, support, examples and documentation, as well as keeping up with ongoing libcamera development. There will also be quite a strong presumption against making signficant code changes unless it seems absolutely necessary, especially any that break existing behaviour or APIs.

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.

You can find documentation here which should help you to get started.

There are also many examples in the examples folder of this repository, and some further Qt application examples in the apps folder.

Installation

Picamera2 is only supported on Raspberry Pi OS Bullseye (or later) images, both 32 and 64-bit. As of September 2022, Picamera2 is pre-installed on images downloaded from Raspberry Pi. It works on all Raspberry Pi boards right down to the Pi Zero, although performance in some areas may be worse on less powerful devices.

Picamera2 is not supported on:

  • Images based on Buster or earlier releases.
  • Raspberry Pi OS Legacy images.
  • Bullseye (or later) images where the legacy camera stack has been re-enabled.

On Raspberry Pi OS images, Picamera2 is now installed with all the GUI (Qt and OpenGL) dependencies. On Raspberry Pi OS Lite, it is installed without the GUI dependencies, although preview images can still be displayed using DRM/KMS. If these users wish to use the additional X-Windows GUI features, they will need to run

sudo apt install -y python3-pyqt5 python3-opengl

(No changes are required to Picamera2 itself.)

Installation using apt

apt is the recommended way of installing and updating Picamera2.

If Picamera2 is already installed, you can update it with sudo apt install -y python3-picamera2, or as part of a full system update (for example, sudo apt upgrade).

If Picamera2 is not already installed, then your image is presumably older and you should start with

sudo apt update
sudo apt upgrade

If you have installed Picamera2 previously using pip, then you should also uninstall this (pip3 uninstall picamera2).

Thereafter, you can install Picamera2 with all the GUI (Qt and OpenGL) dependencies using

sudo apt install -y python3-picamera2

If you do not want the GUI dependencies, use

sudo apt install -y python3-picamera2 --no-install-recommends

Installation using pip

This is no longer the recommended way to install Picamera2. However, if you want to do so you can use

sudo apt install -y python3-libcamera python3-kms++
sudo apt install -y python3-pyqt5 python3-prctl libatlas-base-dev ffmpeg python3-pip
pip3 install numpy --upgrade
pip3 install picamera2[gui]

which will install Picamera2 with all the GUI (Qt and OpenGL) dependencies. If you do not want these, please use

sudo apt install -y python3-libcamera python3-kms++
sudo apt install -y python3-prctl libatlas-base-dev ffmpeg libopenjp2-7 python3-pip
pip3 install numpy --upgrade
pip3 install picamera2

Contributing

Please note that the "main" branch of this repository corresponds to the currently released version of Picamera2 so that the examples there can be referred to by users. Development for forthcoming releases happens on the "next" branch.

We are happy to receive pull requests (normally for the "next" branch) that will fix bugs, add features and generally improve the code. Pull requests should be:

  • Restricted to one change or feature each. Please try to avoid "drive-by fixes" especially in a larger set of changes, as it can make them harder to review.
  • The commit history should consist of a number of commits that are as easy to review as possible. In particular this means:
    • Where one commit is fixing errors in an earlier commit in the set, please simply merge them.
    • Where a commit is reverting a commit from earlier in the set, please remove the commit entirely.
    • Please avoid adding merge commits or any other unnecessary commits.
    • The commit message should have a short single line at the top which is nonetheless as descriptive as possible. After that we encourage more lines explaining in a little more detail exactly what has been done.
    • In general, we don't need to see all the trials, errors and bug-fixes that went into this change, we only want to understand how it works now!
    • Try to ensure that the automated tests are working after all the commits in the set. This avoids other developers going back to an arbitrary earlier commit and finding that things don't work. There can be occasions when other problems cause test failures beyond our control, so we'll just have to remain alert to these and work around them as best we can.
  • Where changes are likely to be more involved, or may change public APIs, authors should start a discussion with us first so that we can agree a good way forward.
  • Before submitting a pull request, please ensure that all the automated tests are passing. They can be run using the tools/run_tests script. Please use tools/run_tests --help for more information.
  • Any documentation should be updated accordingly. New examples and tests should be included wherever possible. Also consider making an entry in the change log.
  • The author of the pull request needs to agree that they are donating the work to this project and to Raspberry Pi Ltd., so that we can continue to distribute it as open source to all our users. To indicate your agreement to this, we would ask that you finish commit messages with a blank line followed by Signed-off-by: Your Name <[email protected]>.
  • We'd like to conform to the common Python PEP 8 coding style wherever possible. To facilitate this we would recommend using our pre-commit hook, which can be installed by doing the following in the root of the repository:
pip3 install pre-commit
pre-commit install

This will install flake8 in a venv and will perform linting of changes prior to committing.

Thank you!

More Repositories

1

linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
C
11,056
star
2

documentation

The official documentation for Raspberry Pi computers and microcontrollers
Python
5,178
star
3

firmware

This repository contains pre-compiled binaries of the current Raspberry Pi kernel and modules, userspace libraries, and bootloader/GPU firmware.
5,133
star
4

pico-sdk

C
3,536
star
5

pico-examples

C
2,763
star
6

noobs

NOOBS (New Out Of Box Software) - An easy Operating System install manager for the Raspberry Pi
Makefile
2,210
star
7

userland

Source code for ARM side libraries for interfacing to Raspberry Pi GPU.
C
2,040
star
8

tools

C
1,876
star
9

rpi-imager

The home of Raspberry Pi Imager, a user-friendly tool for creating bootable media for Raspberry Pi devices.
C
1,668
star
10

rpi-eeprom

Installation scripts and binaries for the Raspberry Pi 4 and Raspberry Pi 5 bootloader EEPROMs
Shell
1,257
star
11

pico-micropython-examples

Examples to accompany the "Raspberry Pi Pico Python SDK" book.
Python
948
star
12

usbboot

Raspberry Pi USB booting code, moved from tools repository
C
897
star
13

debugprobe

C
730
star
14

hats

C
658
star
15

pico-tflmicro

Pico TensorFlow Lite Port
C++
619
star
16

picotool

C++
549
star
17

Raspberry-Pi-OS-64bit

Repository for containing issues on the 64 bit operating system (as distinct from the 32 bit one)
466
star
18

pico-extras

C
459
star
19

pico-playground

C
434
star
20

quake3

C
390
star
21

rpicam-apps

C++
383
star
22

maynard

Desktop environment for Wayland
C
336
star
23

piserver

Raspberry Pi Server wizard to serve Raspbian to network booting Pis
C++
311
star
24

pico-project-generator

Tool to automatically generate a Pico C SDK Project
Python
294
star
25

pico-bootrom-rp2040

C
271
star
26

raspiraw

Example app directly receiving raw data from CSI2 sensors
C
257
star
27

pico-setup-windows

PowerShell
252
star
28

libcamera

C++
211
star
29

utils

A collection of scripts and simple applications
C
148
star
30

openocd

C
141
star
31

windows-drivers

Windows IOT drivers
C
120
star
32

pico-bootrom-rp2350

C
120
star
33

cmprovision

Provisioning system for CM4 products
PHP
97
star
34

pico-setup

Shell
92
star
35

scratch

Scratch releases
79
star
36

usbbootgui

GUI for booting a Raspberry Pi device like Pi Zero or compute module as a device
M4
77
star
37

rp2350_hacking_challenge

CMake
70
star
38

tinyusb

C
67
star
39

rpi-sense

Sense HAT firmware and driver
Assembly
66
star
40

usb-pid

Raspberry Pi Pico PID allocations
63
star
41

gpioexpander

Buildroot based ethernet gadget which gives a host access to PIGPIO to control GPIO pins
Makefile
62
star
42

pico-vscode

The official VS Code extension for Raspberry Pi Pico development. It includes several features to simplify project creation and deployment.
TypeScript
62
star
43

target_fs

Shell
39
star
44

weston

The Weston Wayland Compositor
C
37
star
45

scriptexecutor

Simple buildroot based system for executing a remote script for manufacture programming
Shell
36
star
46

pico-host-sdl

C
27
star
47

pico-feedback

24
star
48

raspberrypi.github.io

Raspberry Pi GitHub organisations
HTML
20
star
49

pytrack

Python
17
star
50

Pi-Codec

Tools for the IQaudIO Pi-Codec / CodecZero sound cards
16
star
51

skygate

Python
15
star
52

style-guide

14
star
53

bookworm-feedback

13
star
54

CMSIS-RP2xxx-DFP

C
13
star
55

armulet

C++
8
star
56

pylibcamera

Meson
8
star
57

libpisp

C++
7
star
58

pico-sdk-tools

Shell
5
star
59

rpi-sb-provisioner

A minimal-input automatic secure boot provisioning system for Raspberry Pi devices.
Shell
5
star
60

pykms

Meson
2
star
61

FreeRTOS-Kernel

C
1
star
62

sweet-b

C
1
star