The Robot Photo Booth

One of my imaginary robots

Can I take your photo?

I had an idea some time ago to create a lightweight photo-booth client using just an android phone and Python running in SL4A. The functionality is as follows:

  1. Speak a greeting to the user
  2. Scan a QR code containing the user’s twitter name
  3. Take their photo
  4. Tweet the photo @ them
  5. Say thank you and repeat!

Added to this, I wanted to give the booth an ‘attitude’ by creating a script of random things for it to say (at random time intervals). The most difficult part of the project was finding a way to run the attitude script when the main process is sitting waiting for a barcode to scan. I tried various approaches, including using multiprocess/threads, however none of these were able to create a timeout in the scanBarCode() function. The simple solution was to create two scripts, one to provide the random talking script running as a background process and another to handle the main grunt work of scanning barcodes, taking photos and tweeting. The development platform was a Samsung Galaxy Pocket, because it’s very cheap and has all the necessary functionality.

The script runs in SL4A r6 and Python r5 (NB that I wasted a significant quantity of time running Python r1… which wouldn’t run any of the scripts I found on the web for tweeting), with the Tweepy library to tweet. The Tweepy library is a special fork that supports the status_update_with_media method, and can be found here. Thanks to Dr Drang for his post on how to tweet images using regular Python. I installed the tweepy plug-in by downloading the main .egg file and then replacing the .py files from the fork with media, seems to work fine.

Here is the code for the barcode scanning and photo taking portion. Note that the QR codes shouldn’t have the preceding @ for twitter names – although this can easily be modified. I’ve been using to generate my standard code:


Here is the main code (which I called

import android
import tweepy
import time

CONSUMER_KEY = ‘key here’
CONSUMER_SECRET = ‘key here’
ACCESS_KEY = ‘key here’
ACCESS_SECRET = ‘key here’
droid.makeToast(“Starting Auth”)
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
droid.makeToast(“Starting Authset”)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
droid.makeToast(“Starting API”)
api = tweepy.API(auth)

picdir = ‘/sdcard/pbooth/’
pictemp = picdir + ‘%05i.jpeg’
piccount = 1

runcontinuous = True

while (runcontinuous == True):
droid.ttsSpeak(“Hello, I’m the robot photo booth! Please show me your QR code”)
code = droid.scanBarcode()
droid.ttsSpeak(“Smile! Taking picture now.”)
droid.cameraCapturePicture(pictemp % piccount)
tweet = “@” + code[1][‘extras’][‘SCAN_RESULT’] + ” here is your picture. Have a nice day!”
api.status_update_with_media(pictemp % piccount, status=tweet)
droid.ttsSpeak(“All finished. Your picture has now been tweeted. Thank you”)
piccount += 1

Picture file names are incremented, so the directory will be over-written each time you restart the script. The talking script is here:

import android, time, random
runcontinuous = True

dialogues = {0 : “Hello, I’m the robot photo booth! Please show me your QR codes and I will take your picture and tweet it back to you. Please put your QR code in front of the camera now”,
1: “I can’t see your QR code properly, is it upside down?”,
2: “I’m bored. Please come and play with me”,
3: “Sorry, it’s nearly my bedtime but I’ll just take one more picture”,
4: “Help! Help! Someone has unplugged me”

while (runcontinuous == True):
droid.ttsSpeak(dialogues[random.randrange(0, 4, 2)])
time.sleep(random.randrange(20, 70, 2))

The dictionary of phrases can be added to in the format number:”text”,. Be careful not to paste in non-ascii characters if using quotes and jokes pasted from the web.

When setting up with twitter, go to and register your new application. Remember to select Read and Write access for your application, otherwise you will waste a fair amount of time as I did.

You can find the output of my photobooth on twitter here:

The remaining parts of the project are to print out a nice A0 size robot, including some instructions and sellotape the camera on the back of it. Job done!

Tagged , , , , , , , , , , , , , , ,

2 thoughts on “The Robot Photo Booth

  1. Patrice says:

    Howdy! Someone in my Facebook group shared this website with us so I came to look it
    over. I’m definitely enjoying the information. I’m bookmarking and
    will be tweeting this to my followers! Wonderful blog and superb design and style.

  2. Marcus says:

    Outstanding story there. What occurred after? Good luck!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: