DIY body cam with a Raspberry Pi


The Rasp Pi has Python bundled into Raspbian Linux, so it's only natural to use that for picture-taking activities. The proper libraries should be installed for GPIO pin operation, and the easiest way to do that is via apt-get:

pi%  sudo apt-get install python-dev python-rpi.gpio

Once the libraries are loaded you'll also need to install streamer [8] and sendEmail [9] before you can execute the Python script that takes the picture:

pi%  sudo apt-get install streamer
pi%  sudo apt-get install sendEmail

streamer takes the pictures and sendEmail lets you initiate an email message from the command line (inside the Python script using a system call), without having an email client running on the Rasp Pi. Once the applications are set up, you can use the Python script in Listing 1 to grab a picture and send it to an email address.

Listing 1

01 import RPi.GPIO as GPIO
02 import time
03 import os
05 GPIO.setmode(GPIO.BCM)
07 GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
09 pic = 0
10 suffix = '.jpeg'
11 fout = ''
12 osout = ''
13 mailout = ''
15 while True:
16   input_state = GPIO.input(17)
17   if input_state == False:
19     fout = str(pic)+ suffix
20     print fout
21     print 'Push Button Pressed'
22     osout = "streamer -c /dev/video0 -b 32 -o " + fout
23     print osout
24     os.system(osout)
26     mailout = "sendEmail -f -a " + fout + " -xu
         -xp 'mypassword' -t
                  -u 'mail test' -m 'spy picture' -s &"
28     print mailout
29     os.system(mailout)
31     pic = pic + 1
32     time.sleep(0.2)

The code is pretty straightforward, with normal library loading and variable initializing (lines 1-13). Every time the button is pressed (line 17), the camera fires (lines 22-23) and sends the picture out through email (lines 26-29). To increment picture file names (fout variable), I built a text string (line 19) that uses a successive integer number (pic, incremented in line 31) each time it goes through the loop (line 15). The string then goes into the external call to streamer using the os.system function (line 24).

A similar process occurs when sending the picture files through sendEmail. A string is built (line 26) and pushed out via the os.system call (line 29). Of course, you'll want to replace my fictitious email parameters (-f, -xu, -xp, and -t options) and mail server (-s option) with your legitimate values.

Using The Body Cam

To use the device, simply fire up the Rasp Pi, open a terminal, and run the Python script:

pi%  python

Make sure the Pi has a working network connection. Each time you push the button, you should receive a new email with a picture at your target email address (Figure 4). Notice the & at the end of the sendEmail string. That queues up the sendEmail commands in the background, so you don't have to wait for the operation to complete before you can take another picture.

Figure 4: The body cam. The PiTFT piggybacks on the Rasp Pi, with the C270 webcam attached through a USB port.

For a truly portable operation, hook the Rasp Pi up to a 2,200Ah cell phone power pack. I also tethered the Rasp Pi to my Galaxy S5 Active smartphone over WiFi. That way, every time the button is pressed, the email note (with the picture), first goes to the smartphone and then out to the Internet over the cellular connection.

Even if some activist, security goon, or Fed tries to take your body cam … too late … the photo is already on your secure email server, miles away from your physical location. Getting out of the confrontation is another story. Best of luck to you, brother.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content