Photobooth with Nikon wireless DSLR camera sync
Tags: wifi, photography, photobooth, python
Published: 2019-02-12 19:30:00

---
title: Photobooth with Nikon wireless DSLR camera sync
published: true
tags: wifi, photography, photobooth, python
canonical_url: https://akent.org/posts/photobooth-with-nikon-wireless-camera/
---

It's almost Valentine's Day, and, long story short, I volunteered to run a "photobooth" for my kid's school class party. The [props](https://www.amazon.com/gp/product/B078Q9XTPW) and backdrop were easy enough, but who really wants to use an expensive Polaroid-type film camera these days? So I cooked up another solution. What if I could use a digital camera, transfer photos wirelessly to my laptop and display them in an almost real-time slideshow on a large screen that the classroom already had? Awesome!

I happen to have a Nikon D5500 DSLR camera, which has a WiFi function built in. I've never actually used this in-built WiFi feature, but as it turns out, it's pretty much perfect for this usecase. By default, it runs its own WiFi hotspot that you can connect to from your phone or laptop. The apps for both mobile and desktop they provide are totally terrible though, bordering on unusable. Luckily, open source to the rescue! The camera speaks [PTP](https://en.wikipedia.org/wiki/Picture_Transfer_Protocol) over IP (PTP/IP). There's a program / library called [gphoto2](http://gphoto.org/) that comes with a tool that can easily sync new photos directly to a folder. In theory you could also use something else like a Toshiba FlashAir WiFi SD card to transfer the image files across if your camera doesn't support WiFi natively.

Assuming you've set up and enabled your camera WiFi hotspot and connected to it from your computer, you can then run this gphoto command to wait for events from the camera, including waiting on any completed photo captures, and immediately copy those images across the WiFi:

```gphoto2 --port ptpip:192.168.1.1 --keep --wait-event-and-download```

Great! Now all we need to do is display these images. I wanted something fullscreen and something to show the latest images straight away, for the shortest possible feedback loop between taking the photo and seeing it on the big screen. I added some "display the latest images" logic to a pretty simple [python script](https://gist.github.com/b90cabb6e80fe5d36a734f3267c3cbc5) that uses [pyglet](https://pyglet.org), an OpenGL python framework, as it was the easiest way I could find to get a fullscreen image display on MacOS.

The process the display script uses is:

- Every 'tick', check if there are new files that have appeared in the data directory.
- For every new file, assign it the median view count of all photos so far, minus a small weighting factor. This allows it to be displayed more often while it's still new. Choose one of these new files at random to display.
- If there are no new files this tick, pick one randomly from the least frequently displayed photos.

The python [collections.Counter](https://pymotw.com/3/collections/counter.html) module made tracking the view counts pretty easy.

To make the photobooth even more fun, I also grabbed one of those simple infra-red [remote triggers](https://www.amazon.com/AmazonBasics-Wireless-Control-Digital-Cameras/dp/B003L1ZYZ6) so the people in the photos can push the trigger themselves. 

The biggest benefit of all of this is the kids get some great photos saved straight away into digital form that can be then easily shared with parents and friends. I hope they all enjoy being the 'customers' of this little photo booth idea!