Can anyone tell me how to detect faces in a static picture using Ruby or Javascript?
-
6WOW! And I thought I was the only one reaching for impossible goals. :-) – Wim ten Brink Sep 09 '09 at 13:46
-
18I can detect faces even without Ruby. – StackedCrooked Sep 09 '09 at 18:22
-
Simple solution: You don't. Complex solution: Use something existing. (Near) Impossible solution: Write something on your own. If you have nothing better to do. – Rakesh Pai Sep 09 '09 at 22:25
-
7You've asked 18 questions palani and haven't accepted any answers yet. If an answer solves your problem then please click the tick to the left of the answer to accept it. – John Topley Mar 05 '10 at 09:33
12 Answers
If you are going to try and write something from scratch, there is a great explanation of the process on the Carnegie Mellon Website - neat graphics too.
However, your best bet is probably trying to hook into the Opensource Computer Vision project. Here is a good tutorial on using OpenCV for facial recognition.

- 6,793
- 2
- 33
- 36
Since the other answers to that interesting question are mostly outdated now, here the 2012 solution:
Using jQuery with jquery.objectdetect:
$("#faces").objectdetect("all", {classifier: objectdetect.frontalface}, function(coords) {
// Do something with the face coordinates
});
Using jQuery with jquery.facedetection:
var coords = $("#faces").faceDetection();
// Do something with the face coordinates
Not using jQuery: Both plugins are based on stand-alone libraries that do not depend on jQuery at all.
In reply to @joeforker who said
"If you really don't understand that the notion JQuery can detect faces is a joke, you need to learn a lot before you will be ready to detect faces."
Or you just have to wait a year or two ;)

- 19,302
- 9
- 64
- 74
-
1Unbelievable progress! Who would believe it is possible in live video feed just with javascript? – Petr Sep 27 '12 at 14:55
It looks like you are new to programming. Perhaps you have an advanced mathematics degree? If you really don't understand that the notion JQuery can detect faces is a joke, you need to learn a lot before you will be ready to detect faces. If you're lucky you can find an easy out-of-the-box solution. Unfortunately, face recognition is in the class of problems that tend to lack easy out of the box solutions. JavaScript is right out.
http://rubyforge.org/projects/opencv/ is a Ruby binding to OpenCV. The pitiful documentation (autogenerated API docs only) at http://doc.blueruby.mydns.jp/opencv/ mentions a face_detect.rb that might be helpful. As with most bindings, you should also consult the documentation for the original library e.g. http://opencv.willowgarage.com/wiki/FaceDetection
You should also understand that face detection (where are the faces in this photo?) is a different and easier problem than face recognition (whose face is it).

- 40,459
- 37
- 151
- 246
-
See it's nothing wrong... if something is not known,frankly tell i am not knowing this... – palani Sep 09 '09 at 14:25
-
I admire your enthusiasm, I just want to warn you that face recognition is a difficult problem. – joeforker Sep 09 '09 at 14:58
I do not know if this question was properly answered or how you resolved it, but I recently encountered this problem myself. I'm currently investigating external API's to implement my solution. The two Ruby API's that I am currently comparing are rdetection and Face.com's API
I'm primarily using it for face-aware image-crop using ImageMagick, so your needs and results may differ.

- 812
- 6
- 6
-
Yeah, I recently saw a gem for face.com and it's explained some in this article: http://hemju.com/2011/03/14/face-recognition-with-ruby/ I havent played with the gem too much yet, though, so I cant provide any extra help. – daybreaker Mar 16 '11 at 19:08
-
awesome, i hadn't had a chance to play with it since I first spiked the idea. thanks! – Denny Abraham Mar 29 '11 at 13:10
Detecting faces reliably is one of the hard problems in Computer Science. Realistically, there's no practical way for you to do it using Ruby, JavaScript or any other application language using current technology. If you tell us why you need to detect faces then we might be able to suggest a practical alternative approach.

- 113,588
- 46
- 195
- 237
Collect a lot of cash and contact these guys for a good solution!
Wikipedia has a good article about this which also explains why you're trying to do something that is still extremely complex to do.
FRGC is also interesting... If you do find a solution, you can take part in this challenge.

- 25,901
- 20
- 83
- 149
This is a face recognition tutorial using Javascript and face recognition APIs using Mashape - http://blog.mashape.com/post/45712257463/face-recognition-using-javascript-and-mashape
It also lets you detect if the person is smiling or not :)

- 612
- 5
- 13
- 14
After some research and help from this thread I've decided to make a rubygem which can be found here:
EDIT: Unfortunately rekognize decided to discontinue their services making this Gem obsolete.
This uses the face recognition API from rekognition.com.

- 2,000
- 18
- 26
-
-
-
1@fatfrog Unfortunately rekognize decided to discontinue their service a couple of years ago, therefor I decided to remove the Gem. Thanks for the heads-up I will edit my answer – dennis Mar 28 '22 at 11:49
Javascript Neural Nets have been used for OCR so should be possible if much harder for faces.

- 8,012
- 33
- 28
Face detection is done using intensive memory based algorithms, which actually go through the image data to detect face like patterns. They may be many facial recognition / Pattern recoginition algorithms and APIS available for free (or for a fee) which you can use/implement with Ruby or Javascript.

- 15,484
- 3
- 42
- 47
-
3I have nothing against javascript, but using it for *face recognition* is like trying to screw a nail. – Esteban Küber Sep 09 '09 at 13:47
-
8
-
1@Welbog: Oh! Of course, but I think you have a bug. Shouldn't it be `$('#faces img').getFaces();` ? – Esteban Küber Sep 09 '09 at 13:50
-
3
-
@palani: It's a joke. @voyager: Look, man. I've never used JQuery. I don't know its syntax very well. – Welbog Sep 09 '09 at 13:52
-
@Welbog: don't worry, I just needed a smart come back and thats all I could nit pick ;) – Esteban Küber Sep 09 '09 at 13:59
-
javascript to query the api or something, its upto the dev. i don't recommend though to implement the algorithms – Rishav Rastogi Sep 09 '09 at 14:01
This should get you started. It's about using OpenCV with Ruby via FFI: http://rubysource.com/detecting-faces-with-ruby-ffi-in-a-nutshell/

- 685
- 1
- 9
- 21