Introduction
The official Raspberry Pi Camera Module is a great tool for vision projects. New versions of Pi OS use the libcamera stack and Picamera2 library.
Setup
- Connect the camera cable to the CSI port (blue tape facing USB ports).
- Enable Camera in
sudo raspi-config.
Python: Capture Image
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.start_preview()
sleep(5) # Camera warm-up time
camera.capture('/home/pi/desktop/image.jpg')
camera.stop_preview()Python: Record Video
camera.start_recording('/home/pi/video.h264')
sleep(10)
camera.stop_recording()