mauricesvay / php-facedetection

Detect face in images in pure PHP
GNU General Public License v2.0
754 stars 255 forks source link

Multi-detection #4

Open Domingo-montes opened 11 years ago

Domingo-montes commented 11 years ago

I finded where to put comments but no familiarized with GitHUb already!!!

I mean the script will can detect more than one face on a pic, like some others around the web..

mauricesvay commented 11 years ago

This library can only detect one face. Multiple face detection hasn't been implemented.

roborourke commented 11 years ago

Hey Maurice,

I've had an idea about how to detect multiple faces by clearing the area of the canvas where one has been detected already and then rescanning. Can you give me any tips as to whether that's just crazy talk or where you'd start if you were going to implement it?

roborourke commented 11 years ago

Hello again,

I've got multi-face detection working on my fork https://github.com/sanchothefat/php-facedetection/blob/master/FaceDetector.php

It's not perfect by any stretch. Overlapping face areas are a problem that I'm not too sure how to work around yet..

mauricesvay commented 11 years ago

The original Javascript implementation had multiple face detection. You might look at it. Your fork is a pretty cool hack however :)

roborourke commented 11 years ago

Merci :)

I'll check out the JS version. I've made a simple plugin that uses face detection in WordPress while it's cropping images here.

jostie commented 11 years ago

Sanchothefat, can't you make the square smaller before removing it. Small enough to stop the recognition but leaving other faces detectable?

roborourke commented 11 years ago

@jostie I don't remove the face but rather remember where it is and skip those points on the image. It's by no means perfect but I wasn't getting consistent results when I skipped over only half of a detected face for example. I couldn't pin down exactly how much face was enough to trigger detection in the end so I kept it simple. If you can figure it out let me know!

If you absolutely require face detection you'd have better luck using opencv directly with a php interface library if there is one. The php implementation is unfortunately very slow to run.

migandhi commented 10 years ago

Example code for multi-detect faces https://drive.google.com/uc?authuser=0&id=0B3IOYEdd-pYSU2N5WTRHYWpfTW8&export=download , the name of the file is hard-coded as in the original sample. I have solved it painlessly , and continued detecting other faces. I didn't have any clue of the above comments. I have just color-filled the rectangle of the face,which allowed further detection. Drawback: here would be that a face may be cut and miss detection due to overlapped region of detection

paskuale75 commented 10 years ago

@migandhi I tried your code, it seems a little too slow, however, are continuing to develop it or is it still? thanks ;)

mauricesvay commented 10 years ago

If you have some spare time, you might want to have a look at the original JS implementation this lib was ported from: https://gist.github.com/mauricesvay/8332158

It had multi-face detection, but I only had the time to port the code for 1 face. It is probably more efficient to finish the port than to launch the 1-face detector multiple times.

migandhi commented 10 years ago

Here an improvement that I see is that the image can be scaled to a thumbnail and then detection can proceed which doesn't have many pixels to scan....// exhaustive, but slow multiscale_detect() is the comment the coder has left in the .js ... that gives count of faces, then using that count the 1 face detection can be looped

migandhi commented 10 years ago

and further improvement can be to scale up the same image co-ordinates if they can be mapped to the larger version

mauricesvay commented 10 years ago

The PHP version already downsamples the image to perform face detection: https://github.com/mauricesvay/php-facedetection/blob/master/FaceDetector.php#L72-L83

migandhi commented 10 years ago

// exhaustive, but slow multiscale_detect() https://gist.github.com/mauricesvay/8332158 in the .js is very true and can't be improved.. return ($this->face['w'] > 0) is the terminating condition as I have guessed it to be. if further scientific interest persists then FFT and Filters can be developed in a laboratory kind of environment... which I assume is available for free in colleges and other research facilities. Intel is a giant and can afford everything.. affordability does come as a constraint