Monthly Archives: June 2014

computing

Building a Photo Booth: Part IV

20140601-142841-52121224.jpg

In the previous posts (Parts I, II and III) I discussed setting up the Raspberry Pi and camera, taking and compiling photos to make a photostrip, and automatically uploading pictures to Flickr. In this post we deal with hardware. The input/output for the photo booth should be exceptionally simple: a light will indicate that the photo booth is ready to take pictures and a single button will start taking pictures.

The Raspberry Pi basic input/output easy through the GPIO pins on the Pi’s board. I found the following tutorials very helpful: Morse Code on an LED and Buttons and Switches. Using these tutorials as a guide, I found that the following circuit should allow all of the functionality the photo booth requires:

20140601-143500-52500654.jpg

Here is what the test circuit looks like in real life:

20140601-143548-52548761.jpg

In order to get the circuit to communicate with the Pi, I used the GPIO library for Python included in the Pi’s operating system. Here is a snippet of code that will wait for the button to be pressed, then flash the LED and take a picture


import time
import RPi.GPIO as GPIO
from subprocess import call

# set input/output pins
out_pin = 4
in_pin = 17

# wait time parameters
pause_time = 0.5
bounce_time = 0.05

# setup GPIO pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(out_pin, GPIO.OUT)
GPIO.setup(in_pin, GPIO.IN)

# take pictures -- this will be more elaborate later
def take_pictures():
	call(["raspistill", "--timeout", "1000", "--output", "pic1.jpg"])
	

# wait for button press, flash light, and take a picture
prev_input = 0
while True:
	input = GPIO.input(in_pin)
	if ((not prev_input) and input):
		print("Button Pressed")
		GPIO.output(out_pin, GPIO.HIGH)
		time.sleep(pause_time)
		GPIO.output(out_pin, GPIO.LOW)
		take_pictures()
		break
	prev_input = input
	time.sleep(bounce_time)

GPIO.cleanup()

Everything worked with the circuit on the breadboard, so I decided to solder the circuit onto a small perf board. The end result turned out looking much nicer despite my rather crude soldering.

20140601-144701-53221589.jpg

In the next (and final) installment, I will put all of the code together for a fully functional photo booth. Hopefully I will have time to make a pretty box to house it.

computing

Building a Photo Booth: Part III

So far (Part I, Part II) I set up my photo booth to take, edit, and combine images to form a photostrip. In order to share the pictures with friends and family, I wanted the photo booth to automatically upload the images to a social media site. I settled on using Flickr because it allows controlled access (pictures can be made private) and it has relatively user-friendly API. The API allows my photo booth software to automatically upload pictures as they are taken.

After a lot of sleuthing and tinkering, I found that this Python implementation of the Flickr API was my best bet. Once everything is set up with Flickr, the API allows you to upload images to your Flickr account with just a few lines of code.

Registering the photo booth with Flickr Before an application has access to any Flickr accounts, it must be registered through Flickr. You can follow the instructions here to register your application. The registration will give you a public and secret key that allow Flickr to authenticate your application. Keep these in a safe place.

Giving the photo booth access to your Flickr account In order to upload pictures to a Flickr account, you need grant the photo booth application access to your account. Here are some instructions on how to accomplish this. Be sure to set the permission ("perms") to "write" (instead of "read" as in the example).

Uploading Images In order to upload images to your Flickr account, you need to store the authentication keys associated with that account somewhere. Mine are stored in a file called “auth-handler” in the same directory as the python code for my photo booth. Here is the code used to upload an image to my Flickr account:


import flickr_api

flickr_api.set_keys(api_key = 'MY_KEY', api_secret = 'MY_SECRET')

flickr_api.set_auth_handler('auth-handler')
user = flickr_api.test.login()

flickr_api.upload(photo_file = "/home/pi/photobooth/pics/tile.jpg", title = "Test Picture")

After running this code, I looked at my Flickr photo stream and this is what I found.

So far everything seems to be working well! Next time, I will be putting together the hardware associated with my photo booth: flashing lights and buttons.

computing

Building a Photo Booth: Part II

In the first installment, I went over the basic setup of my Rpi which is the brain of the photobooth. Today, I am installing some software to process photos, and writing a script which will take, edit and print the photos.

Editing Pictures I will be using ImageMagick to edit the photos. ImageMagick is a powerful suite of image manipulation tools which can be run entirely from the command line, making it perfect for the photobooth. To install ImageMagick on the Rpi, run the command sudo apt-get install imagemagick

ImageMagick includes a tool called “mantage” which combines several images into a single image. I wrote a simple shell script which takes 4 pictures at regular intervals, then combines the images into a single picture:


#!/bin/sh
# Filename: take-photos
# Description: takes 4 photos at regularly spaced time intervals
# and combines the images into a single 2 x 2 montage

# Take 4 pictures with 1 second delay between the pictures
raspistill --width 504 --height 504 --timeout 5000 --quality 75 --output pic1.jpg
raspistill --width 504 --height 504 --timeout 1000 --quality 75 --output pic2.jpg
raspistill --width 504 --height 504 --timeout 1000 --quality 75 --output pic3.jpg
raspistill --width 504 --height 504 --timeout 1000 --quality 75 --output pic4.jpg

# Combine images into a single montage
montage pic[1-4].jpg -tile 2x2 -geometry 504x504+4+4 tile.jpg
convert tile.jpg -density 256 tile.jpg

Here is the output of my first test using take-photos:

20140601-120655-43615094.jpg

Next time, I will go over how to automatically upload the photos to Flickr.