Face Detection and Recognition for Linux

Fixed a bug in the "Face" suit of tools for face detection where the export to F-Spot couldn't deal with already used names for tags. In addition to F-Spot this also exports to DigiKam (although not the full 2.x format) and the files' EXIF data. Please let me know what other exporters you would like to see – what is your favourite photo manager?
Download  |  

What is it?


How does it work?


This is an α quality release, and nowhere is this more visible than in the way these scripts are currently distributed and installed, as well as the – rather special, and somewhat outdated – prerequisites you'll have to meet.


The "Face" suite of scripts is essentially a suite of python scripts. They are known to run on Linux, and while I do not see any particular reason why they shouldn't run on Windows too, I must say I have never tried it (I do not do Windows, except when getting paid for it), and you would be very much on your own trying it. That said, let me know how it went…

Most of the "Face" suite of scripts simply require a reasonably recent python interpreter and the modules which normally accompany such a beast. Any python 2.x (2.5, 2.6 and 2.7 were tested) ought to be just fine.

However, two special (and 4 rather more common) modules are needed for most of the actual work:

Face detection is done using an implementation of the Viola-Jones algorithm from opencv (and, even more importantly, the trained classifier which comes with opencv). This means you will need opencv on your computer, as well as the opencv python interface. Both the pre-2.2 SWIG python interface as well as the newer python interface are supported. Note: there seems to be a bug in OpenCV 2.x which will find too many regions that are not faces. Version 0.1.2-pre and later attempt to work around this bug.
Face recognition (or what little goes under that name at the moment) relies on an implementation of PCA provided by Henning Risvik. Unless you are really lucky and your distribution provides a dep/rpm/whatever for it, you will have to download it from Henning Risvik's website and install it yourself. Make sure to enable the numpy version in setup.py (default is numeric, which is not really very useful).
The Python Imaging Library. This does most of the image manipulations. Use your package manager to install this (it's called python-imaging in Ubuntu 8.04), or get it from http://www.pythonware.com/products/pil/.

In order to determine the orientation of the image, we read the EXIF data where available (if none is available, we have to try the three most likely orientations). You will need both the python bindings to exiv2 as well as exiv2 itself – you can probably install these via your package manager (python-pyexiv2); if not, get the former from http://tilloy.net/dev/pyexiv2/, and the latter from http://exiv2.org/.

Note: this now uses PIL.ExifTags instead.

NumPy is the fundamental package needed for scientific computing with Python. Surely you could get it via your package manager (python-numpy); or you could grab your copy from http://numpy.scipy.org/.
This is used for some minor image processing tasks which should have been left to PIL (and presumably will in future versions). Until then, you can install it via your package manager (python-matplotlib), or grab it from http://www.scipy.org/PyLab.

The "Face" suite of scripts is known to install and run (in some cases with some warnings) on at least the following distributions:

  • Ubuntu 8.04 (development platform)
  • Ubuntu 10.10 (test platform)
  • Ubuntu 11.04
  • Debian 6.0.1
  • OpenSuSE 11.4
  • Fedora 14

In Ubuntu 8.04 as well as 10.10 and 11.04 (and presumably slightly older and never versions of Ubuntu too, as well as relatively new Debian versions), the following ought to install all these prerequisites (the README contains similar installation instructions for OpenSuSE 11.4 and Fedora 14):

# install most dependencies
acer>/home/utcke% sudo apt-get install python-opencv opencv-doc libcv-dev python-imaging python-imaging-tk python-numpy python-matplotlib python-dev unrar wget
# change to /tmp directory
acer>/home/utcke% cd /tmp
# get pca_module...
acer>/tmp% wget http://folk.uio.no/henninri/pca_module/pca_module-1.1.02.rar
# ...and unpack it
acer>/tmp% unrar x pca_module-1.1.02.rar
# change into that directory
acer>/tmp% cd pca_module-1.1.02
# change old_numeric to false in line 18
acer>/tmp/pca_module-1.1.02% $VISUAL setup.py
# if using any Python version other than 2.5, change line 11
acer>/tmp/pca_module-1.1.02% $VISUAL src/numpy_version/nipals.c
# compile...
acer>/tmp/pca_module-1.1.02% python setup.py build
# ...and install
acer>/tmp/pca_module-1.1.02% sudo python setup.py install


Sorry, no distutils, no setup.py – just a bunch of python scripts packed using Fredrik Lundh's Squeeze – a small python script from 1997. Untar face-0.2-pre.tgz, drop the executables someplace in your PATH, the manpages somewhere in your MANPATH, read the README or the instructions above (for the prerequisites) and below (do it!), and enjoy.

If you like the idea, or think this might be useful, or in fact do use it, you might want to donate a few cents, just to keep me motivated – think of it as paying for an App: how often have you paid € 0.99 for something of dubious value?


Pre-release, dated 16.9. This is a pre-release of version 0.2, which will be the first release to allow sorting by (similarity to all images with a given) tag as well as by (similarity to just one) face. Other changes include:

  • face2fspot crashed when the name of a tag was already in use; it now prints an error message and continues.
  • Files containing umlauts (or, more generally, non-ascii charcters) did not work with never versions of Python/sqlite3 in face_find.
  • Added two missing functions to transpose images in face_find when using OpenCV 2.x.
New features:
  • (16.9.) You can now select the category for the tags exported to f-spot in face2fspot; this is important in case the name of a tag was already in use.
  • (28.5.) Exporter to DigiKam. Both database version 3 (digikam 0.9.3) and database version 4 (digikam 1.2.0 to 1.9.0, and presumably all other 1.x versions) are supported; however, in version 4 only one AlbumRoot is supported (anyone using more than one?).
  • (29.4.) The README now contains install instructions for OpenSuSE 11.4 and Fedora 14 in addition to Ubuntu 8.04, 10.10 and 11.04.

Further planned improvements include:

  • Ability to act (tag or dismiss) on several thumbnails at once.
  • Statistical information about the percentage of tagged faces.
  • Some changes to the GUI (recommendations, anyone?).
  • More exporters (currently supported are F-Spot, DigiKam and exporting directly to EXIF; which photo managers /formats would you like to see?).
  • And, presumably, some more bugfixes :-)

Bugfix-prerelease, dated 1.4.2011. Fixes a bug which happened once all thumbnails were sorted away. Also includes a simple sample exporter API in faceDB.py.

There seems to be a bug in OpenCV 2.x which tends to find much to many regions which aren't faces at all. This sort of works around this bug. Should you still suffer from it, you might want to add something like '-s 2' too; this will then only find faces larger then 40x40 pixels, but also less crud.

This also now works with OpenCV 2.2 (in addition to all prior versions), doesn't depend on pyexiv2 anymore, prints the name of the image in the preview, and allows independent resizing of the preview and the thumbnail-selector.

Bugfix-release, dated 23.3.2011. Now also works with Python 2.6. Tested under Ubuntu 8.04 (i.e. Python 2.5, opencv 1.0 and F-Spot and Ubuntu 10.10 (i.e. Python 2.6, opencv 2.1 and F-Spot 0.8), but presumably also works with all versions of Ubuntu in between.
Initial release, dated 16.3.2011. Requires Python 2.5 or older.


  1. Download face-0.2-pre.tgz, unpack it, and drop all files in their appropriate places.
  2. Call "face_find -r DIR1 DIR2 LIST_OF_FILES" where the arguments point to all the places where you keep your image files. Go away. For a long time (hint: while processing speed depends on the actual images, this will take several seconds per image for most current photos).
  3. Call "face_learn". This will take nearly as long (ok, not really, but still enough to get something to eat. Cook yourself a nice meal), and eat up all your available memory (on a 32bit machine, or with a 32bit python, you want to make sure you have the full 4GB (virtual) memory. This is one of the occasions where you might want to close Firefox, OpenOffice and even, sigh, Emacs).
  4. Call "face_sort". Your first job should be to weed out all the non-faces in your database – although you might find it hard not to label a few images on your way…
  5. Once you got rid of all (many) non-face images (and need another meal), you might want to rerun "face_learn".
  6. When adding new images, you might want to rerun "face_find" and "face_sort"
  7. Oh, and in case you are using F-Spot, you would presumably want to run "face2fspot" every once in a while.