Jay Salvat just posted a brilliant plugin that automatically detects faces in a picture. You can download the code from Git Hub or check out the demo here
The plugin is fairly easy to integrate into a social application, all you need to do is add the following code to a page so when you click the ‘detect faces’ button the plugin is run.
you also need to include 3 javascript files. The algorithm for detecting faces was originally written by Liu Liu
$(function() {
$('#detect').click(function() {
var coords = $('#demo img').faceDetection({
start:function(img) {
$('.face').remove();
$('#detect').text('Processing...');
},
complete:function(img, coords) {
$('#detect').fadeOut();
},
error:function(img, code, message) {
alert('Error '+code+': '+message);
}
});
for (var i = 0; i < coords.length; i++) {
$('<div>', {
'class':'face',
'css': {
'position': 'absolute',
'left': coords[i].positionX +'px',
'top': coords[i].positionY +'px',
'width': coords[i].width +'px',
'height': coords[i].height +'px'
}
})
.appendTo('#demo');
}
return false;
});
});
After detecting face how to let users to write which square represents who ?
If 3 face box are shown, I want to get 3 text boxes where user can write names and those 3 names appear over each box when press submit
You need run on a web server in order to work.
It is not detecting faces having beard.
Can someone explain the code – how it works?
help me in my code’s always this error: Error 2: This image is not valid, so it can never execute them properly
Emil , if you run the web application with localhost then u will not get the error “The Image is not valid”
very neet code would be great to add some code to FB Tag the faces on the Blog
Yeah… really nice script with canvas.. but broken on IE8.. didnt test on IE7..
but very nice start !!! ty for share
So what is the practical use of this?
Nice, however you have an error in IE8:
Error 2: This image is not valid.
waw, nice……
Wao!
Excellent plugin
so funny…thanks
Designer and web developer, Co-founder and Technical Director at Harkable.com London. Previously I worked at InMobi, Spotify and MySpace. Interests include photography and making short videos. Also an avid F1 fan. I also run Mega Infographics for your daily dose of the best infographics.
Follow us on Twitter and get in-stream updates.
Subscribe to all the Papermashup tutorials and articles straight to your RSS reader.
Sign up and get all the Papermashup tutorials straight to your inbox.
13 discussions around jQuery Face Detection