One of the things I’ve been longing to do with my mobile photo-sharing site Camura is to offer image annotations, like objects and faces. Over the last couple of years I have been increasingly frustrated by the appearance of face tagging on services like Facebook, and the recent addition of face recognition to iPhoto has brought this frustration to the surface once again. I don’t even want to do something as complex as face recognition - I just want to find faces in an image.
Googling for things like “open source face detector” doesn’t come up with much. The landscape seems to be comprised of mostly expensive for-pay libraries written for Windows, abandoned research projects, and lots of research papers full of equations – but no code that I could get to run.
To make a long post short, it turns out that Intel’s OpenCV computer vision library comes with a face detector example that should work out of the box. Better yet, there are now some decent Python bindings for OpenCV that come pre-packaged with OpenCV for Ubuntu and Debian. You can install them with:
$ sudo apt-get install python-opencv
Now, it seems that most OpenCV face detector examples are meant to be run “live”, usually taking the image from a webcam and highlighting faces with a red box in real-time. However, I have a large database of static images that I want to consider individually, and I simply want to save the face coordinates for later use, rather than altering the picture.
So, with a bit more Googling, I found a Python script that I could chop up and use for this purpose, and here is what I came up with:
An example run of the script looks something like this: