select a face from an image.

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

select a face from an image.

Post by jassing »

I am writing an app that (part of) it is to take a picture against a static background. (ie: Person stands in front of a white (or whatever colour) background, and then (via webcam) grab an image.

Has anyone done anything like auto-selecting a rectangle that is just slightly outside of the persons face?
I figure this can be done by looking at whole image, find pixels that are 'out of bounds' of the defined colour (to account for light variations, wrinkles in the background, say "20% off from white" -- once you find pixels that don't match, that would be the 'face' and then crop the image, starting slightly to the upper and left of the 1st off pixel, then select to just past the last pixel (lower right)

I have next to zero experience manipulating images, so I'm not sure of the best way to go on this...
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: select a face from an image.

Post by Danilo »

Wikipedia: Face_detection leads you to Wikipedia: OpenCV, a cross-platform library.

See http://opencv.org/ for Docs, Tutorials, Downloads.

For example: Ever wondered how your digital camera detects peoples and faces? Look here to find out!

Image

But maybe that's just too much and you are looking for a simpler approach?
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: select a face from an image.

Post by Little John »

Hi Danilo,

thanks for the links, very interesting!
http://en.wikipedia.org/wiki/OpenCV wrote:All of the new developments and algorithms in OpenCV are now developed in the C++ interface.
Unfortunately, I don't know much about C++. Can we access the C++ interface with PureBasic?
Azur
User
User
Posts: 63
Joined: Sat Jan 28, 2012 11:13 am

Re: select a face from an image.

Post by Azur »

User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: select a face from an image.

Post by Danilo »

Little John wrote:Unfortunately, I don't know much about C++. Can we access the C++ interface with PureBasic?
Everything is possible if you find somebody who has some time left for doing it (direct access hack or wrapper). :)
Usually such things need some more time, it is not done in 10 minutes. So I can't help you atm.

Found some articles explaining OpenCV face detection. Start there: "How Face Detection Works" and check some other articles on this site: Seeing With OpenCV - A Five-Part Series

Maybe you can implement the Viola-Jones method yourself directly, with some additional research?
User avatar
idle
Always Here
Always Here
Posts: 5839
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: select a face from an image.

Post by idle »

If you're on windows you can have a look at this example I did a while back

webcam face tracker example.
http://www.purebasic.fr/english/viewtop ... 12&t=37148
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: select a face from an image.

Post by Danilo »

Little John wrote:Can we access the C++ interface with PureBasic?
Had some time, so I used the following code to translate to PureBasic: Seeing With OpenCV, Part 2: Finding Faces in Images

DOWNLOAD: OpenCV244_PB510_FaceDetect_Test_001.zip (3,39MB)

Tested with XP and Win7. It is just a simple test, try with some smaller images (but faces not too small!). ;)

You could also test with other "opencv\data\haarcascades\*.xml" files, for example smile detection.

Example (myself):
Image
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: select a face from an image.

Post by jassing »

idle wrote:If you're on windows you can have a look at this example I did a while back

webcam face tracker example.
http://www.purebasic.fr/english/viewtop ... 12&t=37148
thank you --I'll have a look.
I wanted it to be as automatic as possible.
User avatar
idle
Always Here
Always Here
Posts: 5839
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: select a face from an image.

Post by idle »

Try the openCV example.
In my example I think you might need to specify a threshold range, I can't remember
and I can't run it in the VM to check it.
Windows 11, Manjaro, Raspberry Pi OS
Image
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: select a face from an image.

Post by applePi »

in the Danilo example it works with more than one face
Image

Image
but there are extra third square in the second picture
thanks
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: select a face from an image.

Post by Danilo »

applePi wrote:in the Danilo example it works with more than one face
Image

Image
but there are extra third square in the second picture
thanks
It is a false detection! Did you try to disable your antivirus? ;)

You need to play with the parameters of cvHaarDetectObjects() a little bit. Try setting min_neighbors (last arg for GetObjects) to 3 or 4,
I had set it to 2 in the example. Also, try with other haarcascades from OpenCV package, I just used the default ones.

The images are converted to 8-bit internally by default. Use the following flags for cvLoadImage() to change it:

Code: Select all

Image = cvLoadImage(ImageFileName,#CV_LOAD_IMAGE_COLOR|#CV_LOAD_IMAGE_ANYDEPTH)
Try also flag #CV_LOAD_IMAGE_GRAYSCALE. Everything is very flexible.

Read about the parameter tuning at: Seeing With OpenCV, Part 2: Finding Faces in Images - Parameters and Tuning

Don't use it for robotics with guns! A false detection and you are dead... or maybe kitty cat. :cry:
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: select a face from an image.

Post by Kiffi »

Danilo wrote:It is a false detection!
here's another one:

Image

strange...
Hygge
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Re: select a face from an image.

Post by Rings »

Kiffi wrote:
Danilo wrote:It is a false detection!
here's another one:

Image

strange...
muaahhh, you made my day (monday for special)
thx...
SPAMINATOR NR.1
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: select a face from an image.

Post by dige »

:lol:
"Daddy, I'll run faster, then it is not so far..."
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: select a face from an image.

Post by Little John »

Danilo wrote:
Little John wrote:Can we access the C++ interface with PureBasic?
Had some time, so I used the following code to translate to PureBasic: Seeing With OpenCV, Part 2: Finding Faces in Images

DOWNLOAD: OpenCV244_PB510_FaceDetect_Test_001.zip (3,39MB)
Hi Danilo,

I didn't intend to ask you to do this ... you did it anyway. :-)
Thank you very much!
Now it's time to play with it. :-)

@Kiffi: :lol:
Post Reply