Tuesday, June 17, 2008

FAINT - Search for faces

Lately, I've been playing around a bit with facial pattern recognition algorithms and their open source implementations. I came across many reference implementation but a very few were implemented in Java, and the Eigenfaces algorithm by far happens to be the best amongst them all. During my research around the said topic i happened to stumble-upon an implementation called FAINT (The Face Annotation Interface - http://faint.sourceforge.net). Faint by far the best facial pattern recognition API and as you must have already guessed, it implements the Eigenfaces algorithm.

Now enough of theory talks, how about implementing an example with faint...? Here is one for all you face-recognition enthusiasts. The following example simply searches for faces in a given photograph and thumbnails them. Now, I know thats not face recognition; but be a little creative here. Once you have the facial thumbnails extracted, its never a big deal to look further in the Faint API and find methods which can help you do the real recognition. :) Now, i was a little lazy to set up a pattern recognition database to left the example to the point of facial extraction only.

The Simple Class which extracts thumbnails -

import de.offis.faint.controller.MainController;
import de.offis.faint.model.ImageModel;
import de.offis.faint.model.Region;
import java.io.File;
import java.io.IOException;
import java.util.Random;

public class Main {

private static final String Imagedir = "C:\\images\\fr";
private static final String faintDir = "C:\\Documents and Settings\\roy\\.faint";
private static final String saperator = "\\";
private static final Random randomGenerator = new Random();
private static final boolean moveThumbnails = true;

* @param args the command line arguments
public static void main(String[] args) throws IOException {
MainController controller = MainController.getInstance();
if (controller != null) {
ImageModel imageModel = new ImageModel(Imagedir + saperator + "mgrp.jpg");
Region[] regions = controller.detectFaces(imageModel, false);
if (regions != null) {
System.out.println(regions.length + " people in the image...");
for (int i = 0; i < regions.length; i++) {
Region region = regions[i];

if (moveThumbnails) {
String cacheFilename = region.getCachedFile();

File file = new File(faintDir + saperator + cacheFilename);
File dir = new File(Imagedir + saperator + "faces");
boolean success = file.renameTo(new File(dir, "face_" + randomGenerator.nextInt() + ".png"));
if (!success) {
System.out.println("Error occured whilst moving " + cacheFilename);

Hope somebody out there takes the example further and does something interesting with the learning.


Big Feet said...

Hi, I'm currently doing a project on face recognition and I've downloaded the demo of FAINT.

Do you know where to get the API documentation? Thanks in advance! :D


Anonymous said...

sir, kindly can you give the code for eigen-face approach based face recognition.
I have working knowledge of core Java and currently working on my university project for face recognition.
thanking you...


Anonymous said...

can you please send to me the faint API..Im currently working on a face recognition project


thanks in advance

Michel said...
This comment has been removed by the author.
Michel Lampo said...

I previously posted a problem I had with the program based on the code above but I fixed it. There apears to be a line missing:

Between the following 2 lines needs to the following line:


ImageModel imageModel = new ImageModel(Imagedir + saperator + "mgrp.jpg");
----> needs to come here
Region[] regions = controller.detectFaces(imageModel, false);

Is this because of a new version? I don't know, but this appears to work. I found this with some debugging lines and looking at the source code of the FAINT-api itself. Where I noticed that creating the ImageModel does not read the actual file

ershad said...

Thanks Michel Lampo, i was not able to debug the problem for a longtime, but i am working on it for my project and i came this site again and found your solution. thanks again

Valentin Dorneanu said...

I have an error
MainController cannot be resolved to a type

the de word is underlined here :
(and so it doesn't recognize the MainController and ImageModel either )

import de.offis.faint.controller. MainController;
import de.offis.faint.model. ImageModel;
import de.offis.faint.model.Region;

Valentin Dorneanu said...

IF U MADE ANY PROGRESS WITH YOUR PROJECTS IN FACE RECOGNITION ... give us some help by posting here. Don't just leave us :)
Ok - only if you want to.
thanks in advance - for me it's very urgent

Michel Lampo said...


I don't know how advanced you are with Java so my answers can be a little simple. Please contact me on my email if you want more respons.

1st possible problem: there are spaces in your imports. But this could be from copiing the text.

import de.offis.faint.controller. MainController;
import de.offis.faint.model. ImageModel;
import de.offis.faint.model.Region;
2nd possible problem: did you add the faint jar to your project? Otherwise your IDE can't find the FAINT-classes.


Reginaldo L. Russinholi said...

Hi, is it possible use Fain API on Linux?

After compile your sample successfully, I tried to execute and I received the following message:
java.lang.UnsatisfiedLinkError: /home/reginaldo/.faint/opencv/libguide40.dll: /home/reginaldo/.faint/opencv/libguide40.dll: invalid ELF header (Possible cause: endianness mismatch)

Of course, it's because the libguide40.dll is a Windows lib, but I didn't find any reference about using Faint on Linux.


monduz said...

Hi. I'm developing a project for the face recognition. I want to use faint but I don't find the API documenation and the javadoc. Can you help me? Thanks a lot.


Michel Lampo said...

The only documentation I know is the Javadoc. You need to generate them yourself.

Go to the svn, (http://faint.svn.sourceforge.net/viewvc/faint/), download the source and generate the javadoc.

You will need to look at the code to figure some things out.

Mahesh C said...

Hello Roy,

I wanted to recognize eye on a non moving face, which will be uploded by user.
Will this work with Java, or you know any suaitable library for the same.

Mahesh C

Rahul Roy said...


Faint is rather poorly documented, you got the right URI to start with.

-- Rahul

Rahul Roy said...


As for identifying the features like eyes, mouth, etc are concerned you need to take the image and create a negative form of the same. That should set the stage for you to then identify the features and their locations.

Refer the following links for details -



Anonymous said...

Great post!!!

Anonymous said...

any one knows where should i find documentation for faint api

omar said...

i tried the FAINT API but the result was not as expected, it always catches other items on the page and considers them as faces, it will detect the faces though with them, any configuration i should perform in order to get more reliable results?
feel free to send me mail to omar.bilani@gmail.com

alex said...

@omar: Increase the ScanWindowSize in order to reach fewer regions.

Anonymous said...

Hi guys, just to mention that Faint is a great API, it works well, but it relies on JNI using Win32 binaries, so it won't run on Solaris (which is what we tried to use it for) and presumably might struggle on some 64-bit Windows systems. It uses Intel's OpenCV library, and whilst we managed to compile that for use with Solaris, there is another JNI dependency which uses a library that's for Intel chips only, and so it's no good for Sparc.

Great article though, thanks!

Anonymous said...

i have a problem in the method
>> the error is "Error occured whilst moving 00000002.png"
please help me to fixed this problem
thanks in advance

dariusgeo said...

That error message seems to come from here
if (!success) {
System.out.println("Error occured while moving "
+ cacheFilename);
so... it is a problem with renaming the the generated thumbnail file.
I reached the same error message and I went to private static final String faintDir = "C:\\Documents and Settings\\roy\\.faint"; (this should be your user.home directory, I saw the thumbnail file was successful created.
In conclusion, i guess you've received that message because already have the thumbnail file in you user.home directory.

dariusgeo said...

I tried to get the code using Eclipse and SVN plug-in, from the location that Michel gave it : http://faint.svn.sourceforge.net/viewvc/faint/, but without any success.
Does somebody did this successful?
Please post the instructions.
Thanks in advance.

Uwe said...

Hello Darius,

Just try the following svn-URL:


Just tried it a minute ago...



dariusgeo said...

Thank you Uwe,
Lot of thanks, Sir.

dariusgeo said...

Hi Uwe,
Thank you, Sir. Lot of thanks.
For the release1.3 project I needed the following jars, in order to get it compile : metadata-extractor-2.3.1.jar , j2ee-1.4.jar and axis-1.4.jar.

dariusgeo said...

I generated the javadoc for the release1.3 project. I can send you it zipped if you send an e-mail to dariusgeo@yahoo.com .

dariusgeo said...

Thank you, Sir.

dariusgeo said...

Thanks, Uwe.

Anonymous said...

Hi, I've used this library to perform face detection in a photo upload service we provide. We found the library to be very good, but had to make some modifications first - one of the plugins uses OpenCV, which requires some Intel binaries which are Windows-only, so we had to drop that plugin to run it on a UNIX platform. Also, it's hard-coded to use a .faint folder in the user's home directory, so we changed it to use resources bundled inside the JAR instead to facilitate deployments to multiple environments; these are a couple of caveats, but the library does its job very well.

Anonymous said...

hey I know this may no longer be useful to you but just for the benefit for anyone chancing upon this:

to solve the 'import cannot be resolved errors', you have to import the the jar file (download faint.jar from sourcefourge) to the src of the project & add the jar file under java build path, where it contains your JRE jar files.

P.s.to go to java build path, right click project>properties>java build path> libraries> add jar

leilatong said...

@Valentin Dorneanu

hey I know this may no longer be useful to you but just for the benefit for anyone chancing upon this:

to solve the 'import cannot be resolved errors', you have to import the the jar file (download faint.jar from sourcefourge) to the src of the project & add the jar file under java build path, where it contains your JRE jar files.

P.s.to go to java build path, right click project>properties>java build path> libraries> add jar