Jump to content

Locate A Face In An Image Using PHP + GD


JustinK101

Recommended Posts

Hello,

 

I am looking into using PHP (GD Library) to scan images and locate a face inside an image. What is the technique to do this?

 

Example: Let's say I am given an image which shows a figure photographed from the waist up, how can I locate the face in the image?

 

I have been told to look into Fast Fourier Transforms (FFTs) perhaps?

 

Thanks for the help.

Link to comment
Share on other sites

don't know if gd has it, but maybe you can make a psedo magic wand tool like photoshop has to select the outline so to speak, it will not be perfect, but you can probably get it to track a line around by using a neighboring pixel idea.  like if pixel 5,5 is black then check  if any of the 9 surronding are black if so then you start this multi directional testing until you find all lines (greater than 1 point) that navigate from the start point and all the way around back to it.  It be a challenge but it could be done if you can read on a pixel to pixel level.

Link to comment
Share on other sites

This is, unfortunately, the sort of application that people spend years developing and tuning.  if you wish to proceed, you are going to need to do a lot of research on this topic- it isnt easy.  the good thing, though, is that it has been developed, the only problem is that you will have to do a lot of work to get some source code.

 

http://computer.howstuffworks.com/facial-recognition.htm

Link to comment
Share on other sites

I did some face recognition research while at uni.  What's in the public domain is complex, crude and not very effective.  The reason is that an effective face recognition system has enourmous value, and will be snapped up by the government or military immediately.

Link to comment
Share on other sites

If you think about using an image editor such as Macromedia (sorry Adobe) Fireworks or Adobe Photoshop.

The only way you would be able to cut a face (or any object) from the image is IF the background is a pure colour.

 

Even then you could still have problems.

 

I personally think you would have too many problems trying to do this using website programming.

 

I would suggest trying something which is built more for this sort of stuff such as Flash or Java (Not JavaScript, Java)

 

Maybe adding the same crop tool.

 

Link to comment
Share on other sites

You need to scan the image for skin tones (difficult as there are lots if them for each creed!).

 

how ever you can plot the areas of an image that have a skin tone and assume that the largest one is the face - this depends on the image having one face - mulitple faces requires a bit more thought...

 

I'll have a look for the functions to scan the colours...

 

brb.

Link to comment
Share on other sites

But if you look at an image of a face, the face itself can hold multiple skin tones.

You think, your eyes

Your hair

Your Lips

 

All of these are Different colours

Also need to think of the following

Cheeks normally redder (or if Asian / black then darker) than rest of face

Some photos, the nose comes out almost white (Not sure about black people)

 

This is programming think now.

Logical.

 

I want to crop my face out of an image

I would get a picture of myself with the background a solid bright colour (White or something)

Then I would upload this into my image editor

Then I would crop the BACKGROUND not the face

Then Delete the background, (Should only have me left)

 

Then I would have to manually crop my face from my body

 

Use this logic for your application.

Stop trying to work out how to get a face

Try and work out how to delete the background.

 

Link to comment
Share on other sites

Giving folks a crop utility is (although not what you ideally want) pragmatically the best option. There are loads of ajax/php utilities out there, and it would involve adding only one extra step to whatever process is involved, be it registration or whatever. Google uses it for picture choosing in Gmail, for example.

Using GD to scan pixels individually and work out areas would, aside from being insanely memory/CPU intensive, be so hit and miss you would need to have a human check each one, and I would guess, 9 times out of 10 ask it to try again- much better and faster to go for the user crop method.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.