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) {
controller.setScanWindowSize(1);
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];
region.cacheToDisk();

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.

27 comments:

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

Rgds,
kianan@gmail.com

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...

abhee.ray@gmail.com

Anonymous said...

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


uploadsdotph@yahoo.com

thanks in advance

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

Anonymous 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;

Anonymous said...

PLEASE :
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

Unknown 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.

Thanx

Unknown 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.

a[dot]mondoni[at]gmail[dot]com

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.

Regards,
Mahesh C

Rahul Roy said...

Michel,

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

-- Rahul

Rahul Roy said...

Mahesh,

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 -

http://www.java2s.com/Code/Java/2D-Graphics-GUI/ImageColorEffectBrightnessContrastNegative.htm

http://www.ecology.su.se/jmatrixnet/

Anonymous said...

any one knows where should i find documentation for faint api

Unknown said...

Hi,
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
Thanks

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
region.cacheToDisk();
>> the error is "Error occured whilst moving 00000002.png"
please help me to fixed this problem
thanks in advance

dariusgeo said...

Hi,
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:

https://faint.svn.sourceforge.net/svnroot/faint

Just tried it a minute ago...

Greetings,

Uwe

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...

Hi,
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

Anonymous 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