Assignment 2: In Your Face

Even little Canon PowerShots are actually quite smart... for example, yours actually tries to identify faces in each shot. It's not the smartest, but it is pretty good at finding faces and can use that ability to help select where to focus on.

In this project, we're going to use that face recognition ability to control how we view another camera. However, the PowerShot will not control the other camera directly. The computing resources available inside a camera are nothing compared to what you can have available by "networking" a camera to a dedicated computing system. In this project, you'll be doing something a little too ambitious to fit inside a camera: two cameras will be tethered to a computer that will collect images from both the PowerShot and another camera. The result will be a time-lapse video making clever use of the face recognition data from your PowerShot.

Your Project

You're going to make a simple time-lapse movie. Doesn't sound too hard, does it? Well, it sort of is. You see, all of the better codecs involve not just compressing one frame at a time, but interpolating between frames. To do that, one needs to have key frames both before and after the frame currently being compressed. Not a big deal, but that does tend to mean you need more memory than the PowerShots make available. There's also the little issue that most cameras don't allow you to run programs inside them at all.

Thus, your project here is simply going to involve using a Linux PC to command a camera to take a series of images which the computer will upload and straightforwardly convert into a lime-lapse movie using standard software tools and a command line that I'll give you. The cute thing is that you're not going to tether just one camera, but two: a Canon PowerShot A4000/ELPH115 using chdkptp and either a UVC webcam using fswebcam or an IP network camera using wget. If you'd like, I will allow you to substitute a firewire camera or a cell phone camera for the webcam or network camera, but the details of how you implement tethered capture of images from those devices are up to you. You'll be combining the images from two cameras to make your time-lapse movie consisting of at least 100 frames.

Basically, you are to write a program/script to run under Linux that will capture frames at regularly-spaced intervals from two cameras simultaneously: a pair of captures at a time. The capture from the webcam or IP network camera is the primary image you'll use for each time interval. However, the PowerShot images are going to be conditionally merged with those images in an interesting way. Each time the latest PowerShot image contains a detected face, you'll extract a close-up of the face from that image and include it as an inset in the other image. That would actually be somewhat difficult if there wasn't already software that essentially can do it for you....

You should scale the image resolution to a manageable size for video, e.g., 640x480 instead of 16MP. Of course, any inset image must be scaled to be small enough to fit within that lower-resolution image to be used as a video frame. A good limit would be to keep the inset image to 320x240 pixels maximum -- one quarter of the frame. Once you have collected all the images, your program is to combine them into a movie in any standard format. There is a lot of open choice here -- the goal is to make sure you understand the basics of tethered camera control, I'm not asking for anything fancy.

Stuff To Know About

Here are the basics of tethered control for each of these devices and how to splice the images together. You also will be given info on how to access tethered cameras in 108 Marksbury.

chdkptp

chdkptp is an incredibly powerful way to implement tethered control of the A4000. It's also not the easiest thing to install, and it needs to be able to find the Lua modules that it uses to do way more than you'd expect it would be doing with Lua. Most importantly for this project, it allows shooting images and sending them back to a host via USB without ever storing them on the SD card in the camera -- which is an important distinction given that SD cards start to fail after as few as 10,000 write cycles.

The command you need to use is rs, also called remoteshoot. A complete list of the command is in USAGE.TXT, which is about as close as you'll get to a real manual for this tool. It's worth noting that the GUI generally doesn't work under Linux... not that you'll want to use a GUI for this assignment.

Extraction Of Faces Using EXIF

As noted above, even lowly little cameras like your Canon PowerShots actually can recognize faces (if you enable face detection). Most digital cameras can, and they record the face information in the EXIF data. The bad news is that each camera brand (and in some cases, different models within a brand) uses different EXIF fields to store the relevant info. Fortunately for us, there is a wonderful little piece of free software that knows how to read that info for us....

The real key is a free program called ExifTool that was written by Phil Harvey. It knows how to extract a mind-bogglingly-diverse set of field values from an image file. It is actually structured as both a stand-alone program and a Perl library. He also wrote a little example code called facetest.pl that uses the library to extract face data and create a copy of each image with the faces boxed. I've slightly modified that program for you so that it simply creates a new image file with just the extracted face image: getface.pl file.jpg will create a copy of the face extracted from the file as a file with the same name in the subdirectory called tmp. If no face was recognized and tagged in the EXIF, it doesn't make a file. Note that the ExifTool library and ImageMagick (described below) must be installed for there Perl scripts to work.

fswebcam

fswebcam is a very nice tool for grabbing images from a webcam. I'd suggest you invoke it once per image you wish to grab... which doesn't work so well with some other webcam software because some cameras don't keep their exposure adjusted while not being explicitly accessed. This software allows you to specify a short sequence of frames be requested before taking one for real, thus allowing the camera exposure to correct. There is a man page documenting the options; -s is the option that skips frames before capture.

wget

wget is a not-so-simple program that can fetch URLs. Since cameras like the DLINK DCS-900 make the current image available at http://camera_url/IMAGE.JPG, it's a rather simple matter to fetch the current image. Beware that wget will make a new filename rather than overwrite an existing file named IMAGE.JPG. As discussed, the reason I like wget is because it provides options for filling-in WWW forms so that you can control exposure settings.

A 640x480 network camera has now been made available for you to grab from at http://garage.ece.engr.uky.edu:10078/IMAGE.JPG:

ImageMagick

ImageMagick is a powerful library for image processing -- and a suite of command-line tools that serve as a demonstration of the library and make ImageMagick very easy to use in scripts. The functionality of the tools overlap each other considerably, and one can do most things in convert. In particular, a command like:

convert -size 640x480 xc:black \
	image1.jpg -geometry 640x480 -composite \
	image2.jpg -geometry 100x80+529+0 -composite \
	image3.jpg

Will create a black canvas of 640x480 pixels, scale image1.jpg to fit it, scale image2.jpg to 100x80 and put it in the upper right corner, and then write the resulting composite image to image3.jpg.

mencoder

mencoder is a video encoder co-developed with mplayer. Command lines look very scary, but if you want to do it and it involves video encoding, odds are mencoder can help. For example:

echo "Mencoder Pass 1..."
mencoder mf://*.jpg -mf w=320:h=240:fps=15:type=jpg -vf scale=320:240 -ovc lavc 
-lavcopts vcodec=mpeg4:keyint=120:vbitrate=1600:vpass=1 -o /dev/null 
echo "Mencoder Pass 2..."
mencoder mf://*.jpg -mf w=320:h=240:fps=15:type=jpg -vf scale=320:240 -ovc lavc 
-lavcopts vcodec=mpeg4:keyint=120:vbitrate=1600:vpass=2 -o /dev/null 2>/dev/null
 |tail -1
echo "Mencoder Pass 3..."
mencoder mf://*.jpg -mf w=320:h=240:fps=15:type=jpg -vf scale=320:240 -ovc lavc 
-lavcopts vcodec=mpeg4:keyint=120:vbitrate=1600:vpass=3 -o movie.mpg 2>/dev/null
 |tail -1

Due Dates, Submission Procedure, & Such

You will be submitting source code for your tethered control program or script, a make file (which does whatever is necessary), and a simple HTML-formatted "implementor's notes" document.

For full consideration, your project should be submitted no later than November 5, 2015. Submit your .tar or .tgz file here:

Your email address is .
Your password is

Which type of student are you?
Undergraduate registered for EE599
Graduate registered for EE699


http://aggregate.org/CACS/ Cameras as Computing Systems