Face recognition



I have implemented a simple face recognition class for OF. The demo video shows tracking and recognizing one face from amongst 6 training faces. I have also tested it successfully tracking and identifying two different faces in the video frame. It is intended to work in concert with the ofxCvHaarFinder class.

It uses principal component analysis adapted from “Seeing with OpenCV Part 5”
and http://derindelimavi.blogspot.com/2008/-…-nma-2.html

In addition to the basic OF 006 release, the demo app requires


If you give it a spin, let me know what you think



Two faces:


One face:



this looks really cool. Theo, Arturo and I were playing around with Surf to try face recognition. I saw someone on vimeo already did this but no code :frowning: I will try to get in inside OF and post.

I think combining simple face tracking to narrow down the searching and then use surf to id the person will work great.


Nice :slight_smile: That’s really stable.

Todd + Robert: Did you have a project in mind you wanted to use this for? Or just to try it out…?


Hi, thanks for the replies.

I’m guessing this is the video you meant: http://vimeo.com/4990304, he has two good code links there as well.

I wasn’t familiar with surf. Though I may have seen a demo video like the vimeo one. I am also curious about HMMs for recognition, but I’ll be happy with whatever works.

Kyle: I am training a recognition system with images of friends and acquaintances (drawn from all the likely places, plus personal memorabilia I have) towards the creation of an interactive piece.


wow, sorry for off-topic, but OF and UCSD? very cool collaboration.


Hi Robert,

I was able to compile your code and run it. Thank you for posting it. Could you please give some insight about how to train it to other faces?




Technically you could use any square formatted cropped image of a face.

However,I have a short faceExtractor program (adapted from the dirList example) which runs the same face detection code as the faceRec program. You can feed it a list of files and it will try to identify faces, saving them out at the proper dimensions for use in the faceRec code. It’s here:


Sorry the svn download is a bit messy, lots of extra directories, etc.

Please let me know if you have difficulty getting it to work. What are you making?


Hi Robert!

Thanks for the second program. I think I got your programs distinguish two people. I am preparing for a theatrical production and am evaluating various interactivity means.

Thanks again. This is great stuff.



Very Interesting Piece
I try to run it a Linux Box. but, an error happen. Cant load the “train” images, so de XML file is not created.
I had change format names without spaces and nothing happen always the same error.
Any idea?


Great piece robert and found it SUPER useful, thanks so much for posting.

No major problems getting it running in 0700, though weird Xcode 4/of 7 were reading the faces.txt document as having a space and a carriage return on each line (so had to change the line:

inImage = inImage.substr(0, inImage.length()-1);
inImage = inImage.substr(0, inImage.length()-2);


Using it in a “security app” prototype for the computer that uses both face recognition and a palm scan taken using an old scanner to confirm identity (working on getting an electric scale with USB I just got on ebay implemented to check and make sure you’re not a terminator as well, as you can tell this is very SERIOUS stuff). I’ll make sure to post as soon as I get it cleaned up. Thanks again!


this is an old thread but did anyone get this working with a newer OF version on OS X?

thanks stephan.


Thanks @rtwomey.

An even older reply. Yes, on OSX 10.11.6 with OF 9.3 it works jus fine out of the box.
Not many changes to code whatsoever apart from a few deprecated terms. Can post it if necessary.

Basically I created a new project, with ofxCV and ofxOpenCV and ofxYAML as addons.
Mind the recognizer.setup(1, 132, false, “faces”); line, which deals with the amount of photos in your faces folder.


Just tried this on windows 10 with OF 0.9.6. You don’t need the ofxYAML addon at all and the code works still.


Could you please tell me how you fixed the deprecated terms?

Many thanks.


Hi, since it’s been a while I can’t really remember which issues I was having at that point. Sorry. Perhaps you can post a screenshot of the problems and that’ll help figure things out.


I am getting multiple errors about that there is no conversion function from ofPixels_ to “unsigned char”.


hmmm looks like I might have been using something different altogether since I can’t seem to find the specific project file for this thread any more :confused: From the comment I think I was referring to this code actually but since I had multiple tabs open I mixed them up: FaceRecognizer opencv


excuse my newbie reply… I’m trying to download the faceRecTester folder (http://svn.roberttwomey.com/of/faceRecTester/), is there an easy way to do it?