Introduction: Code Your Own High End Photo Booth
This project started out like many other photo booth projects, but it kept growing.
So, I'll walk through my project but I'd recommend that if you are trying to decide what you want to build then make a decision and stick with it. Or you could be in for months of design and redesign.
This is my journey over the last few months.
About the Photo Booth
What It Is The LRP Photo Booth is a kiosk style unit with a graphical user interface prompting users to pose for four individual photos and deliver them through a variety of methods. It is low cost, portable, and easily modified to meet the needs of any indoor event. This unit has been designed to 1) deliver a memorable product to the user in the form of a branded individual photo, 2) a collection of guest photos from the event to the customer, and 3) create traffic for the host.
What it Does
The user will be prompted to press an on-screen button to start the automated process. The monitor will display a preview and countdown to the camera capture for each photo and finally present the finished photo. For each finished photo, the user can choose to accept the image for delivery or start over. For each user cycle, the photo booth takes four photos that can be sent to a user provided email address, posted to a blog, and printed. Operation of the Unit Menu Options Options to determine how the photo booth will operate are set using the standard menu. They are divided into options that should be set for each event, or as often as necessary. And options that should be set with major configuration changes.
Clean Files – Moves all completed montages and individual images to an archive folder located at /home/pi/PB_archive/. Each time this option is used a new folder will be created using the date and time as a folder name. This will make keeping events separated for distribution as convenient as possible.
Set Up The Event – Opens a dialog window allowing the host to create and preview custom borders for each event. Host (Company Name) and Event (message to the customer) can be customized for each event. The date uses the system time to build a label; therefore, labels should be refreshed for each event. Printer options for the number of photos to be produced for each event is established here. Some customers prefer to have a collection of printed photos for an album.
Print Montage – Check box giving the option to enable the printer. The printer must be connected and powered on. Different printers may be installed and used if properly enabled in the Set-Up Menu. The default printer is always used by this program.
Email Montage – Check box giving the option to enable sending email to a user provided address. The user will be prompted to supply their email address, and if this option is checked it will send it to them immediately. No error checking is done to ensure that the supplied address is formatted correctly in order to save time and confusion during the experience.
Blog Montage – Check box giving the option to enable the blog post to a host provided address. This is simply an email address entry and can be used to send each photo to a secondary account for manual upload, which may be a safer option with an adventurous crowd, or to an account such as Blogger, which allows email post to be published.
Enable Sound – Check box giving the option to play sounds when a photo is snapped and certain buttons are pressed. This option requires speakers to be added.
Provide Feedback – Checkbox that when enabled provide a dialog that accompanies the progress bar at the bottom of the screen. This option may be useful during troubleshooting to determine a faulty routine or to better understand the underlying processes.
Set Up Printer – Opens the printer setup dialog. The software will look for the default system printer. It must be configured here. The option to print one (1) or two (2) copies of each photo is available when setting up each event on the Operation tab.
Set Up e-Mail – Opens the .muttrc file for editing. Mutt must be installed and set up for the email or blog options to work properly. The default set-up is for Gmail (Google). The text file explain which options must be configured by the user and which are constant.
Update Post Text – Opens a dialog window displaying for edit the text, as it will appear in the email delivered to the user and posted to the blog. Host can also update the blog post address. The blog-post address must be provided by a blog host that allows email post, such as Blogger eg: firstname.lastname@example.org.
Raspberry Pi 3 Model B Motherboard
ASUS VS228H-P 21.5" Full HD 1920x1080 HDMI DVI VGA Back-lit LED Monitor
Canon Selphy CP1200 Wireless Color Photo Printer
Raspberry Pi Camera Module V2 - 8 Megapixel,1080p
JBtek 4 Channel DC 5V Relay Module
Linux version 4.4.13-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) ) #894 SMP Mon Jun 13 13:13:27 BST 2016 Raspbian GNU/Linux 8 (jessie)
imagemagick/stable,now 8:220.127.116.11-5+deb8u4 armhf
python3/stable,now 3.4.2-2 armhf
mpg321/stable,now 0.3.2-1.1 armhf
mutt/stable,now 1.5.23-3 armhf
xscreensaver/stable,now 5.30-1+deb8u2 armhf
Step 1: Collect Your Parts
This is a list of the major parts I chose:
- Raspberry Pi 3 Model B Motherboard - The RPi is an amazing little piece of work. It is powerful enough to do most anything that you would need. I've spent a lot of time with microprocessors because they need so little power and resource, but this inexpensive powerhouse is well supported and runs a full Linux distribution. ~$50 anywhere (you will need to look at the model of RPi that you get and make sure to get the right kind of SD Card. The package that I show here comes complete with a power supply, SD Card, and a few other things for a really reasonable price.)
- ASUS VS228H-P 21.5" Full HD 1920x1080 HDMI DVI VGA Back-lit LED Monitor - Nothing special here but I did require HDMI inputs due to the RPi outputs. I wanted one with sound so I bought this. However, capable of sound doesn't mean that it has speakers. I bought external speakers later. ~$110 on Amazon
- Canon Selphy CP1200 Wireless Color Photo Printer - This is a cool little printer that makes neat little pictures. It is not well supported in by the RPi so, you might find a work-around in my code. Don't judge too harshly. ~$100 on Amazon
- Raspberry Pi Camera Module V2 - 8 Megapixel,1080p - There are several types of cameras out there that will work but this one is native to the RPi. That has obvious advantages, but don't discount some of the other libraries out there. Originally I used gphoto2 library to control my Nikon D3200 and it worked great.The inability to use an external power supply for the camera made me rethink. Ultimately, the 8mp camera proved to be plenty powerful for this project. ~$30 on Amazon
- JBtek 4 Channel DC 5V Relay Module - This module is a leftover from my original concept. Before I determined that a full graphical user interface was necessary I was going to use a series of LED indicators to prompt operation. And I was certain that I wanted to use some external lighting. I still use 12v LEDs as indicators and have the option to turn on ambient lights when needed, so I kept this in the package. ~$9 on Amazon
- Other hardware. Keyboards, power supplies, interconnection wires, project boxes, power strips, LEDs...
I went through a ton of parts. I used boxes, screws, wires, zip ties, zelcro strips, and a grip of other things that I had laying around from a wide range of other projects to get to my final design. I suspect that you will too.
Step 2: Let's Get That Little Computer Running
This part is exciting if you have never worked with a micro-computer before. But, if you are going to attempt this project I assume that you have at least thought about it. Nonetheless, it's cool to see the little thing start up.
Before you put it all together you have to build the micro SD card. The RPi doesn't have a permanent hard drive so this image has to be burned from another computer. It's really easy and there's a video explaining it here.
This is not my thing so I'll defer you to the experts, but here are the steps that you will see in the video:
- Build the image
- Card goes in the slot.
- Mouse, keyboard and monitor gets connected.
- Connect the power supply.
- Configure your time and location.
- Configure your keyboard.
- type startx in the command line
We always want to start the GUI because that's where our our program will run. There are two options to make this happen:
- Use the Menu button to select the Advanced->Raspberry Pi Configuration screen and select 'Auto login'
- Type 'sudo raspi-config' at the command line, then arrow to boot options, then arrow to 'B4 Desktop Autologin'
Now you have a completely functional credit-card-sized computer. Only thing left to do here is upgrade/update all of the software.
I know that you're excited but this step is break worthy. Use the menu bar to locate the WiFi logo in the right corner. select a reliable WiFi connection and verify that you can get to the internet. Once that is complete then find the command prompt again and type 'sudo apt-get upgrade'. This will upgrade your distribution. After you have answered a question or two it will begin. Now take that break.
Step 3: Let's Get the Right Software Installed
Before I go much farther I'd like to share with you a trick that I use almost every time I work with the RPi. Since I have a kiosk computer set up I like to remotely manage it from another computer, through the command line. Sometimes even my iPad or iPhone. I downloaded Putty from here. There are a lot of choices but the basic .exe will do the job. Any ssh (secure shell client) will work. Simply type 'hostname -I' at the command line of your RPi and use the IP Address to connect from your remote machine. This will make life easier. I often program on a remote machine and use the host to execute and text.
If you are set up then we can begin to collect the packages that we need and test the environment.
Image Magick is a great tool that we will use every time we open our program. It can be complicated to learn how to use everything that it can do. But, we don't need to do that. Visit here to find a list of commands that can be used from the command line. I'll explain in much more detail later.
type "sudo apt-get install imagemagick' at the command line to install the latest packages
Python should already be installed on every Rasbian distribution but we will look for and install the latest version.
type 'sudo apt-get install python3'
mpg321 is an audio player that is light enough to run fast and has some options that allow us to change volume from the command line.
type 'sudo apt-get install mpg321'
Sound can be easily confused by the RPi because we are using an HDMI monitor that can receive and process sound. It is sometimes necessary to force the audio output to the right place. If no sound can be identified using whatever method you choose then check your speakers for proper connection and power, and then investigate the following commands: Where n is the output : 1=3.5mm jack, 2=hdmi. type 'amixer cset numid=3 n' to set the audio output manually.
xscreensaver is optional for this project because there is no interaction with the photo booth. I just don't want the screen to be burned. And the photo screensavers and neat.
type 'sudo apt-get install xscreensaver'
mutt is a favorite mail program with all of the old timer command line gurus. It still has great value to Python scripters because it has command line interfaces that will allow us to send mail automatically.
type 'sudo apt-get install mutt'
set-up is a little different but it wont break us. You can edit your .muttrc file (the configuration file) by typing going back to the command line and typing 'leafpad /home/pi/.muttrc'. The example file I attached is my setup for gmail. They work well together and this setup only requires you to modify the first few lines. A much deeper explanation of mutt and some other mail options can be found here.
Step 4: Add the Camera and Test It Out
The Raspberry Pi camera that we are using is another neat little gadget. For the money it is hard to beat the functionality and power that you get in this little package.
Physically install the camera with the small ribbon cable that came with it if you want to, but it is really too short to be usable for anything except testing. You've got several options from a longer cable to full on mods.
You may want to consider a case for your camera too. I have a black case that provides a way to mount it fairly easily. I had this one, but it didn't work for me so I had to look around some more and ended up with the one in the picture from Sparkfun.com and it works exactly the way it should. A longer cable and a good case will serve you well.
Here are the steps to get the camera working:
- Install the camera.
- Follow the instructions in this video to get the cable right.
- Secure the camera in some type of enclosure to protect it from damage.
- type 'sudo raspi-config' into the command line once again. When menu gives you the option to 'Enable camera' you should select that option, press 'Enter', then 'Finish'. The system will want to reboot now. (If there is an error on after reboot then the camera cable is install incorrectly. No big deal, just make sure that the contacts of the ribbon cable are inserted into the connectors properly on both the computer and the camera.
- After reboot go back to the command line and type 'sudo apt-get install python3-picamera' to get the latest camera packages for Python3. Reference this page.
- Back to the command line, type 'raspistill -o myfirstpic.jpg'. Just as a note, you can enter commands remotely to control the camera. In this case the command will turn on the camera and take one picture. Type 'ls' and you will see 'myfirstpic.jpg' listed there if everything worked. We now know the camera works.
- Now let's check the Python3 packages. This takes some code writing but it's not hard. I like to use nano for editing so type 'nano cam_test.py' to open a new file for editing and type the following:
camera = picamera.PiCamera()
Press Control-O to save your work, then press 'Enter' to verify the filename
Press Control-Z to exit Nano editor
Type 'python3 cam_test.py' and the script will run, leaving you with a photo in your pi (root) folder.
Step 5: Printer Setup Is Pretty Easy.
I mentioned before that the printer I used, the Canon Selphy CP1200, was not fully supported. But that's not a big deal. Regardless of the printer you choose you must still ensure that you have the proper packages. Head to the command line and type these two commands:
'sudo apt-get install cups'
'sudo usermod -a -G lpadmin pi'
The first one installed the packages and the second added pi as a printer user.
CUPS uses a web based interface that you can learn about here. It's a decent video that shows the whole setup. You will see that there are a few different ways to get to the printer port. I use the following address: http://127.0.0.1:631 to access the CUPS interface.
There's no real magic here. You'll be up and printing in no time. Find your printer and make it the default.
But let's test it from the command line, because that's how we need it to work. Earlier we took a picture with our newly installed camera and named it 'my_new_image.jpg'. So let's try to print from the command line. You will type 'lp my_new_image.jpg'. If you have correctly established your printer as the default then you should have an image coming out of your printer right now.
Step 6: GPIO Ports Are Money
One of the benefits of using the RPi are the exposed GPIO ports. (General Purpose Input/Output ports) To unshroud the mystery of how computers actually interact with the world; this is it. Ports that can listen for a signal (input) or produce a signal (output). You'll see the diagram showing how the pins are designated and how they look on the RPi. It's pretty easy except for the numbering system. You'll have to pay particular attention to the name of the port as opposed to the number of the port.
I said before that I originally intended to use a series of flashing lights and a button for control of the unit. Much has changed, but I elected to keep the GPIO pins functioning to add some entertainment. I'll explain a little as I lay out the Python code.
#define GPIO / pins
AMBIENT_LED = 24 # physical pin 18
PRINT_LED = 22 # physical pin 15
POSE_LED = 18 # physical pin 12
READY_LED = 23 # physical pin 16
Now that I have mapped the physical pins to GPIO ports I can also give them usable names, like READY_LED. This allows an easier time while coding turning them off and on at will. you will see in the code how we turn them on and off.
The relay that we chose works great with just a single wire from the GPIO pin to the relay input. No need for clamp resistors like if we were using regular LEDs. You can see in the photos the blue wires connecting the two units directly.
Power your relay from the power supply and you'll be in business. Keep in mind that I didn't use the ambient light control that I declared above. It was another good idea that I wasn't ready to develop but not quite willing to kill yet. I still might do something with it. This section is short and you can completely ignore it if you like. Everything will still run as expected.
Step 7: ImageMagick
Most of our work will be setting up the GUI in tkinter, which I've already done, and making cool pictures to print out. You can just print out a regular old picture like the test we did a couple of steps ago, but I recommend making a montage. I said before that ImageMagick is a command line tool for graphics. It does a ton of stuff and can get really complicated. We will stick to just a few of the commands to build our montage:
Convert is mainly use here to make all of the thumbnails, headers. and borders for our photos during runtime. However, there are a few placards that we display as prompts along the way and this is how we create them:
convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 90 -fill red -gravity center label:"Grab a prop,\nstep back,\nand look awesome! \nYou've got 10 seconds!" prop.gif
convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 150 -fill red -gravity center label:"Watch the\nflashing yellow\nlight..." pose.gif
In this case convert actually creates an image rather than converts, but it does a lot of converting too. Powerful stuff.
Montage is the breadwinner because it produces the final picture. If we do it right then it will look great. Two commands from the actual code are below. The first snippet looks unassuming but it will take all of the pictures (*.jpg) and arrange them in a 2x2 tiled grid (-tile 2x2) with a 5 pixel border (-geometry +5+5) and name it whatever we want.
montage -tile 2x2 -geometry +5+5 *.jpg "+l_montageName+".jpg
This code snippet adds a nice header with the event name and a footer with the date to our image. Follow the code for a second: make a montage that is tiled 1x3 with a +5 pixel border from ...header.jpg, ...image.jpg, and footer.jpg then name it image.jpg.
montage -tile 1x3 -geometry +5+5 /home/pi/GUI/Example/header.jpg /home/pi/Pictures/"+bandg_imgname+".jpg /home/pi/GUI/Example/footer.jpg /home/pi/Pictures/"+bandg_imgname+".jpg
Step 8: Make Your Folder Structure
There is a little work that we need to do to get set up. Many of the files that we use inside the program can be created on the fly, but not all. And we have to move them around during processing, so it is really location, location, location.
Type the following commands at the command line:
That should take care of the folder structure. It is important because we will move files around during processing and if a name is incorrect we will have errors. Double check it to make sure that you have all of the folders named appropriately. The easiest way if to use the GUI to do this.
There are many more folders already there but we don't need to be concerned with them now.
Step 9: Moving Files Into Your Folders
There are a lot of files that go into the GUI folder. I know its a strange name but I named it then built all of the code around it. Sorry.
Like I was saying, move all of these files into the GUI folder. That's it. There are 11 of them.
1.gif, 2.gif, 3.gif, 4.gif, and tiles.gif are all stock photos.
trans_logo.gif is my logo. Unless you just love Lininger Rood Photography then you may want to replace it. Make sure that you use the exact same name and size.
There are two sound files (camera-shutter-click-07.mp3, button-16.mp3), a database file (PB_shelf.db), a text file with the email text (PostText.txt), and the main program (PB.py)
Check again that all 11 files are in the GUI folder.
That's all that we need to copy. The rest of them we can make.
It's time to use some of that ImageMagick trickery that we learned a few steps back. These convert commands will make the images that we need. This is a little bit different type of command, but it's fairly self explanatory.
Now move to the Example folder by typing in the command line:
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 90 -fill red -gravity center label:"Grab a prop,\nstep back,\nand look awesome!" prop.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 150 -fill red -gravity center label:"Grab a prop\n and pose\n in..." pose.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 90 -fill red -gravity center label:"The last one is for\nthe Bride and Groom.\nGrab the chalk board\nand leave a message.\n You've got 30 seconds." bandg.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:1 1.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:2 2.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:3 3.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:4 4.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:5 5.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:6 6.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:7 7.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:8 8.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:9 9.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:10 10.gif'
'convert -size 900x900 -font URW-Chancery-L-Medium-Italic -pointsize 210 -fill red -gravity center label:10 10.gif'
'convert -size 450x25 -font URW-Chancery-L-Medium-Italic -pointsize 20 -fill red -gravity center label:'----- write something that identifies you here -------' borderthumb.gif'
'convert -size 480x44 -font URW-Chancery-L-Medium-Italic -pointsize 30 -fill red -gravity center label:'Gongrats to the new Bride and Groom' header.gif'
'convert -size 450x53 -font URW-Chancery-L-Medium-Italic -pointsize 30 -fill red -gravity center label:'Date goes here' footer.gif'
Now for the About files. Its a good idea to keep some notes on your build and I like to do it in an About file. We've made a folder already and now we just need to make the file. MS Word does the trick, or even Libre Writer. Just open a file, write whatever you want, then save it as About.htm in the About folder. Remember the name is important.
There it is. That's not all we need but the rest will come out in the processes.
Step 10: Let's Run It
We need to test to make sure that we have everything in place, and then we will dress it up some.
Do all of this on the RPi, not the remote terminal. We cannot run our script from a remote terminal because it doesn't have a proper screen to display the results on. It just doesn't work. Some things do, but this does not.
At this point we should have all of the program dependent files in place and the python script should run. We put the main file at /home/pi/GUI/PB.py, so lets get there. It is easier to use the graphical desktop to navigate through the folders and take inventory. However, when it is time to do work we will switch over to the command line.
It is time to do some work. So, open the command line prompt and go to root:
type 'cd' to get to root
type 'cd GUI' to move to the GUI folder
type 'python3 PB.py'
You should see the main screen of our program with a menu bar, thumbnails, and a button right in the center. It may look a little strange, and the center may be a little off. That's because I have no idea what size monitor you used and I wrote the code for mine. This may seem daunting to fix, but it's not terrible.
The console is a favorite for coders and those that love daily scripting but it's not so great for application like this. Let's make an icon for it. We learned to create image from scratch so let's make one for our application. Type these commands at the command prompt to make an icon for us:
'convert -size 64x64 -font URW-Chancery-L-Medium-Italic -pointsize 50 -fill red -gravity center label:"PB" logo.png'
Now we can make the icon file.
type the following commands into the command prompt:
Nano can be tricky if you are not familiar with it. Now that it is open you will type normally. Type the following scripts into your editor to create the desktop icon:
Name=Name to be shown on desktop
Comment=My comment Icon=/home/pi/logo.png
Type=Application Encoding=UTF-8 Terminal=false
Once you have everything in the right place and saying the right things, then use the command to write the script to file, then , and finally >Control-Z>
You will see an icon on the desktop with the label that you created. Try it out. Doubleclick it.
I mentioned that we needed to create some files at runtime. It's runtime. So, admire your work for a minute then find the menu at the top. It works like any other menu.
The three choices are:
The File tab has the option to Exit and display the About page that you made.
But for now, head straight to the Operation tab and select 'Set Up the Event'.
You will see a dialog box with some of the files that you just created. You only made the thumbnails that you see here so we have to actually make the files that we are going to use in our montage.
The two entry fields may have some leftovers in there from my work. And it probably doesn't match the example labels in the dialog box. Let's fix it now. Be creative and type something into the fields, then press the big button at the bottom 'Create New Image Label'.
It takes a few seconds to makes them all. It will take your entry in the fields, store that information for next time, create labels (that we didn't have before), make thumbnails to display, refresh the thumbs that you see, and show you what you made. That's that. Click 'Done'.
Now go to the Set-up Tab and familiarize yourself with the options there. Everything should be in working order but it's fun to play with the setup. Again, this is where you do the routine operations.
Some things that you'll want to do is to click Update Post Text and update the information there. You will be sending out emails and posting to my blog. maybe good for me but not so good for you.
Now for the big show. Click the 'Click Here to Start!' Button.
You should recognize all of the tiles that you created flipping through and giving instruction.
Pose and have some fun.
If everything works the way it's supposed to, then you'll see the final product presented right there. And you'll have the option to try again or have it sent to you by mail and printed. Don't forget to turn on your printer.
Go ahead and test it all out. Click the 'This is It!' Button.
Step 11: Put It All Together
This is my least favorite part and the part I know the least about. If you have cables running all over the place, like I did, and you chose to use extra power supplies, like I did, then it'll be a little more challenging to get it all mounted.
You'll want to figure something out that put's your camera in a good spot and secures your monitor in the right place. I build a kiosk from 1x1 pine connected to a wooden disk and eventually covered it with some interesting drapery fabric.
It's on you to figure out if you want curtains around a big wall mounted Goliath or a tabletop unit.
This is where I'll leave you. Putting it all together the way you see it.