Skip to content

Raspberry Pi Photobooth

jallwine edited this page Aug 15, 2014 · 18 revisions

Setup

picamera module

A photobooth can be a way show off your wacky side or just a way to remember an important event such as a birthday party (or both!). In this tutorial, we'll show you how to set one up with your Raspberry Pi and camera module. First, install the picamera python module.

sudo apt-get install python-picamera

Camera Preview

Open IDLE either from your desktop or through the menu at the bottom left. IDLE is an integrate development environment (IDE) for python. We'll be using it to input and run our photobooth python script. Let's start by taking our first picture. Click File - New Window, or press Control+N. In the new window, enter the following:

import picamera     # module for controlling the camera
import time         # module for adding delays

try:
    camera = picamera.PiCamera()   # initialize the camera
    camera.start_preview()         # start previewing
    time.sleep(5)                  # wait for 5 seconds
    camera.stop_preview()          # stop the preview
finally:
    camera.close()                 # close the camera

Save the file by clicking File - Save or by pressing Control+S. Name the file photobooth.py. To run your script press F5. You should see a preview of what the camera can see for 5 seconds before it closes. Now we'll edit our program above to behave like a photobooth. If you don't see a preview, then you may need to troubleshoot your camera connection or enable the camera in raspi-config settings.

Taking Pictures

Ok, now we're ready to turn our setup into a photobooth. To do so, we'll need to save 3 photos with a 5 second delay between each one. Let's go one step at a time.

Capture a photo

To take a picture with the camera module use the capture() method:

camera.capture("photo0.jpg")

Let's edit our photobooth.py script to take a picture after waiting 5 seconds. Can you find where to put it? Once you've added the capture line to your program, run it again by pressing F5.

Display the photo

To display the photo we'll be using the Image Magick command, display. In a terminal, type the following command:

display photo0.jpg

If it doesn't show up, you may need to install Image Magick:

sudo apt-get install imagemagick

Save two more photos

Modify your photobooth.py script to save 2 additional photos, photo1.jpg and photo2.jpg. Make sure to wait 5 seconds between each photo to allow time to change your pose! Make sure all three files are saved correctly by running the display from a terminal. You can view thumbnails of all of them at once using this command:

display 'vid:photo*.jpg'

If all three images are saved correctly when you run your script then you're ready to move on!

Compositing

Compositing is when you combine multiple images together in various ways. In this case we want to combine our three images into two strips that fit on a 4"x6" photograph as shown in the image below.

Photobooth strips

We'll start by cropping our images to be square, before we combine them.

Cropping

The dimensions of our photos are 1920x1080. You can verify this by using the identify command (another Image Magick command).

identify photo0.jpg

Each image in our strip needs to be square.

Clone this wiki locally