Facial Recognition in 14 Lines Of ColdFusion

Posted By : todd sharp Posted At : January 21, 2010 2:05 PM Posted In: Java, ColdFusion

60

I was doing a bit of research on a potential project when I stumbled across faint, a Java facial recognition library and decided to give it a quick try.

The bad news is that the documentation is literally non-existent. So I did a bit of poking around the Jar and quickly found an 'OpenCVDetection' class. I dropped the faint Jar in my class path, restarted CF and about 5 minutes and 14 lines of code later I got the following result:

If you spend any time around me you've heard me babble on about why Java integration is one of my absolute favorite things about ColdFusion. This demo is exactly why I say that. Sure, the code behind this is massive and complex, but look at how easy I can leverage that hard work:

<cfset detector = createObject("java", "de.offis.faint.detection.plugins.opencv.OpenCVDetection") />

<cfset pathToOriginal = expandPath("test.jpg") />

<cfset thumbDimensions = createObject("java", "java.awt.Dimension").init(100,100) />

<cfset faces = detector.detectFaces(pathToOriginal, 1) />

<p>original img:</p>

<img src="test.jpg" /><br />

facial recognition:

<cfoutput>
    <cfloop array="#faces#" index="f">
        <p>face: #arrayFind(faces, f)#</p>
        <cfset thumbnail = f.toThumbnail(thumbDimensions)>
        <cfset img = imageNew(thumbnail)>
        <cfimage action="writeToBrowser" source="#img#" />
    </cfloop>
</cfoutput>

Stay tuned for more fun as I dig deeper into faint!

Comments (60)

Raymond Camden's Gravatar In my Comicbook Guy voice: "Best. Demo. Ever."

Scott Stroz's Gravatar I have 2 words for that: Wow!

Ed's Gravatar Dude! This really rock!

Akbarsait's Gravatar This is Amazing and Great!

Joseph Lamoree's Gravatar This is so amazing, it makes me lightheaded. See what I did there? It's funny because the project is named faint.

Raul Riera's Gravatar That is pretty awesome... with that title I DONT EVEN WANT TO SEE your Google Analytics for today (actually I do :))

John Mason's Gravatar Cool stuff, thanks for sharing

Rachel Lehman's Gravatar Totally awesome! You make it all look so easy!

Steve Good's Gravatar Much cleaner and probably more precise than the PHP port I was working on. Nice work!

Raymond Camden's Gravatar "Much cleaner and probably more precise than the PHP" - Did you really need to say that? ;)

Ernest Breau's Gravatar This is great, I look forward to more.

Todd Sharp's Gravatar Thanks all! Just hope my wife doesn't see this - she hates that pic but it's all I had on my work PC! :D

Brian Swartzfager's Gravatar That is pretty darn cool! Nice work!

Jim_Collins's Gravatar That is extremely cool!

Brian Swartzfager's Gravatar So I just took a look at the page for Faint you linked to, and noticed this line:

"Simple-Context-Filter - Recognition filter avoiding duplicate occurrences of a person on a single photo"

That would imply it can actually compare one facial instance to another and determine if the face belongs to the same person (a step beyond just determining what part of a picture constitutes a face). Have you tested that aspect yet, or is that next on your list? :)

Raymond Camden's Gravatar How would you recreate a case where you have N pictures of 1 person in 1 photo? Clones?

Grant Copley's Gravatar Great work! My problem is always where to look
for Java library's like this. How did you find this one?

Brian Swartzfager's Gravatar @Ray: Yeah, clones would work. :) But seriously, I'm guessing you could use Fireworks or Photoshop to copy two different pictures of the same person into a single image file and then subject that file to Faint, see what happens.

Andy Sandefer's Gravatar The force is strong with this one...

Tony Garcia's Gravatar Kick ASS!!!

Todd Sharp's Gravatar @Brian - that is exactly where I'm looking to go with this.

Todd Sharp's Gravatar @Grant - just lots of Googling man :) It's always good to keep tabs on what the Java community is up to also. Keep an eye on sources like JavaLobby at dzone.com for example.

Bob Silverberg's Gravatar Much as I hate to be a me tooer, dude, that is awesome!

Sami Hoda's Gravatar Same Q as Ray - how sophisticated is it - will it pick up dupes? We all want to know more! Keep it up.

Joshua Scott's Gravatar ColdFusion Rocks! WOW!

John Allen's Gravatar Oh My Goodness! That makes programming fun.

Scott P's Gravatar sweet - good work sharp

Lola LB's Gravatar Just a wild thought . . . would it also work with objects? Say, for instance, you've got a set of 5 photos and and in 3 photos there is a subject wearing a red dress. To complicate the matter even more, in 2 photos, red-dress subject is in a group of several people. I don't want the face . . . subject in photo 1 is dark-skinned while subject in photo 2 is light-skinned.

Brandon Moser's Gravatar Definitely passing this demo around the office. Great find and demo. Thanks.

Gary Fenton's Gravatar It's good at detecting faces (so your own Facebook app could simply prompt the uploader of a new photo to identify each face it outlines. But it's not very good at identifying who the person is.

I found I had to train it on lots of photos before it was confident enough to learn who's who. Very nice app and library though. It will get better with time no doubt.

Asha's Gravatar cool stuff!!!

Andreas Schuldhaus's Gravatar definitely cool! Thanks for sharing!

Andy's Gravatar Great article.
Dumb question, but where do you put the .jar file for coldfusion to use it? Do I need to register it in the cf admin somewhere?

Todd Sharp's Gravatar @Andy -- you can place it in cf_root/lib (or place it anywhere and add that particular directory to the classpath via Java/JVM in cf admin) and restart CF.

You should also be able to use javaloader (http://javaloader.riaforge.org).

Todd Sharp's Gravatar @Gary - yeah, that's what I'm seeing too - I trained it on a bunch of faces (via the Java app) and it's still not recognizing me. Sadly I think it would be even less possible on the server because it doesn't seem to recognize the files I'm training in my tests after the request ends. Still digging....

Gary Fenton's Gravatar I get the feeling the code looks more at the bitmap itself to identify individuals rather than proper facial analyses that would produce vector maps of facial features and whatnot.
I say that because the GUI app produces munged up bitmaps to show the workings of its analyses, but if it did use vectors and points then why doesn't it show them instead?

One of my projects has a need to look through a database of 1000's of images to find matches so it would need to be accurate without the need for training and importantly, way faster than Faint.

Todd Sharp's Gravatar @Gary: From what I understand it uses the Eigenface method behind the scenes. http://en.wikipedia.org/wiki/Eigenface

James Moberg's Gravatar "Recognition filter avoiding duplicate occurrences of a person on a single photo"... does this mean that a group photo taken at a "Twin Convention" will only identify faces for half of the people in the photo?

Search for a photo of twins and determine if it works or not:
http://www.bing.com/images/search?q=twins

Brent Frye's Gravatar This demo is amazing, but this library is extremely resource intensive I had issues keeping CF running on my dev box and it kept maxing out both cores of my CPU. I would say FAINT is far from being ready for production, but still an amazing feat.

Gary Fenton's Gravatar @James, your assumption is correct for this software which I've been told uses a 23 year old algorythm! Newer software is capable of telling apart identical twins at lightening speed! See here:
http://en.wikipedia.org/wiki/Facial_recognition_sy...
I've Googled for a while and found descriptions of some amazing software but all of it is either commercial or for academic research.

Side tracking slightly, check out this (unavailable) software that takes a low res pixelated photo and turns it into a high res image. http://people.csail.mit.edu/celiu/FaceHallucinatio...

Leigh's Gravatar @Todd - Very nice find!

@Gary - Too bad Face Hallucination is not publicly available. The test results are surprisingly accurate.

Gary Gilbert's Gravatar Todd, very cool in deed!

An old colleague of mine was building "Target" recognition software for Uncle same in his spare time back then that was cutting edge stuff. I think its pretty darn cool that you can find a library like this just out there in the wild.

Interesting would be to build a photo album that automatically mapped the coordinates of the faces of pictures and allowed you to indicate who's who only once, scan all your pictures and apply facebook like hotspots...

Tony of the Weeg Clan's Gravatar dude.

Chris Tierney's Gravatar I put the .jar into the ColdFusion9/lib directory and restarted the service. Then copied your code and ran it. It seems that when I call "detector.detectFaces" it bombs. I can output to the screen before
the call but anything after that never appears. Any ideas?

DanGl eneck's Gravatar Maybe, as a experiment/project, you could create a pass-face like interface in coldfusion? Passfaces are graphical passwords that use faces as a unique verification technology for secure logon.

Kamil's Gravatar Holy cow! Indeed very powerful!

coldfusioner's Gravatar Scary, but very cool indeed!

sf's Gravatar Aww, this was a really quality post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get something done.

mbt's Gravatar This article has great reference value, thank you very much for sharing, I would like to reproduced your article, so that more people would see it.

nooree's Gravatar Very Cool!!!!!!

coach bags outlet's Gravatar I really like your article, I support your point of view

wholesale sunglasses's Gravatar thank you for sharing!! i would like to make love to you for this awsome news.

coach bags outlet's Gravatar I really like your article, I support your point of view

Rolando Lopez's Gravatar This is great! Good job Todd.

BTW, you need a spam filter for your comments :)

Rob Gonda's Gravatar Posts like this make me miss CF ... what a great language ... amazing work Todd, keep it up.

todd sharp's Gravatar @Rolando - i'm actually using cfformprotect - I'm shocked those got thru...

@Rob - thanks man - we miss you in the CF world - what are you up to these days?

Navoice's Gravatar Hey dude, Its an awesome work done, but i m new to CF, can anyone just let me know how to get the code running. Please i want to work in the field of face recognition and i do work in java, but new to CF pls help me.

Tayyab Hussain's Gravatar Hi-

I added the path c:\inetpub\wwwroot\faint.jar in
coldfusion class path butb I recieve an error.
Please help

todd sharp's Gravatar @Tayyab - what was the error?