Skip to content

Recipes

We have put together some example programs for common things people would like to do with their camera.

Start a preview and take a photo

The preview will display for 2 seconds, and then the camera will take a photo called test.jpg.

from picamzero import Camera
from time import sleep

cam = Camera()
cam.start_preview()
sleep(2)
cam.take_photo("test.jpg")

Start a preview and record a video

The preview will display while the camera records a 5 second video called test.mp4.

from picamzero import Camera

cam = Camera()
cam.start_preview()
cam.record_video("test.mp4", duration=5)

Take a timelapse sequence

The preview will display and the camera will take 5 photos with a 1 second interval between each photo.

The images will automatically be numbered sequence-0.jpg, sequence-1.jpg etc.

from picamzero import Camera

cam = Camera()
cam.start_preview()
cam.capture_sequence(filename="sequence.jpg", num_images=5, interval=1)

Take a black and white image

The camera will take one black and white image. (No preview is started in this example).

from picamzero import Camera

cam = Camera()
cam.greyscale = True
cam.take_photo("bnw.jpg")