Take photos on Raspberry Pi

2023-12-23 python raspi

raspi-still seems to be deprecated.

how to use camera module on 64 bit rasiberry pi.

sudo apt install -y python3-libcamera
python3 -m venv --system-site-packages ~/venv/

Sample code with picamera2.

from picamera2 import Picamera2, Preview
from time import sleep

camera = Picamera2()

preview_config = camera.create_preview_configuration(main={"size": (800, 600)})
camera.configure(preview_config)

camera.start_preview(Preview.QTGL)

camera.start()
sleep(5)

metadata = camera.capture_file("test.jpg")
print(metadata)

camera.stop_preview()
camera.close()