Code and Hacks

Stuff I've stumbled on or figured out... mostly Perl, Linux, Mac and Cygwin.

My Photo
Name:
Location: CA, United States

Perl hacker, investor and entrepreneur.

Wednesday, May 6, 2009

Facial Detection and Recongition in Perl

I just recently came across the new facial detection features in Picasa, and I have to say I am very impressed. This is a very useful feature and well implemented; once again Google has set the bar. Unfortunately, it is only available in the web version, and I have way too many photos to upload. Further, there seem to be more privacy concerns with a web version of a tool like this.

So, I was very excited when I saw a brief mention of presentation about OpenCV from a Ruhr.pm meeting (thanks to Yanick's blog). Maybe this was the tool to implement facial detection/recognition in my photos locally.

Without going into much detail, OpenCV is a library of routines for facial detection, recognition, and similar computer vision tasks. So far, I have only experimented with the facial detection part and read a bit about the facial recognition routines. There is a handy Perl binding (Image::ObjectDetect) for the facial detection part. With it and reference to the slides from Ruhr.pm, I was able hack together a very simple script to look for and highlight faces in my photo collection.

While there were many false positives and some missed faces, OpenCV and the script show promise. Most of the missed faces were either very small or profiles, and there is another "cascade" (essentially a set of configuration presets to the detection algorithm) that might yield better results for profiles.

Reading about facial recognition from the OpenCV site was a bit underwhelming, though. Apparently OpenCV only supports one method of recognition, Principal Component Analysis. Which sounds like it has some sever limitations. From the site:

However it does have its weaknesses. PCA is translation variant - Even if the images are shifted it wont recognize the face. It is Scale variant - Even if the images are scaled it will be difficult to recognize. PCA is background variant- If you want to recognize face in an image with different background, it will be difficult to recognize. Above all, it is lighting variant- if the light intensity changes, the face wont be recognized that accurate.

Not exactly a great marketing pitch! PCA doesn't sounds like the most suitable method for recognizing faces from arbitrary photos. I haven't played with it yet, but that's on the todo list.

To sum it all up, OpenCV looks like a great tool. I'll update this blog as I continue to experiment with it and my homebrew version of PicasaWeb's facial detection/recognition features. If anyone else has had experience with OpenCV or other facial detection/recognition tools (particularly those with Perl interfaces) I would love to hear about it.

Labels: ,

2 Comments:

Blogger Scott said...

Any luck with OpenCV 2.0? Based on your blog, I gave 1.0 a shot, was fairly interested in the results, but then noticed 2.0 was out, thought it might work better (perhaps it wouldn't think bricks or rust were faces). Uninstalled the .deb (ubuntu jaunty), compiled latest trunk opencv from svn, now I can't get Image::ObjectDetect to work anymore. I've tried deleting/reinstalling it to no success.

January 26, 2010 at 6:43 AM  
Blogger Mark said...

Scott, I haven't had a chance to revisit this or try the new version. The bindings for Image::ObjectDetect probably haven't been updated for v2. It looks like it will take a bit of XS work to patch them together. There isn't much XS in I:OD, but XS is not my strong suit. You could try contacting the author of Image::ObjectDetect or diving into the XS yourself. Sorry I can't be more helpful.

February 3, 2010 at 5:47 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home