select a face from an image.
select a face from an image.
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...
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...
Re: select a face from an image.
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!

But maybe that's just too much and you are looking for a simpler approach?
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!

But maybe that's just too much and you are looking for a simpler approach?
-
- Addict
- Posts: 4778
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: select a face from an image.
Hi Danilo,
thanks for the links, very interesting!
thanks for the links, very interesting!
Unfortunately, I don't know much about C++. Can we access the C++ interface with PureBasic?http://en.wikipedia.org/wiki/OpenCV wrote:All of the new developments and algorithms in OpenCV are now developed in the C++ interface.
Re: select a face from an image.
Everything is possible if you find somebody who has some time left for doing it (direct access hack or wrapper).Little John wrote:Unfortunately, I don't know much about C++. Can we access the C++ interface with PureBasic?

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?
Re: select a face from an image.
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
webcam face tracker example.
http://www.purebasic.fr/english/viewtop ... 12&t=37148
Windows 11, Manjaro, Raspberry Pi OS


Re: select a face from an image.
Had some time, so I used the following code to translate to PureBasic: Seeing With OpenCV, Part 2: Finding Faces in ImagesLittle John wrote:Can we access the C++ interface with PureBasic?
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):

Re: select a face from an image.
thank you --I'll have a look.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
I wanted it to be as automatic as possible.
Re: select a face from an image.
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.
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


Re: select a face from an image.
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)
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.

Re: select a face from an image.
here's another one:Danilo wrote:It is a false detection!

strange...
Hygge
Re: select a face from an image.
muaahhh, you made my day (monday for special)Kiffi wrote:here's another one:Danilo wrote:It is a false detection!
strange...
thx...
SPAMINATOR NR.1
-
- Addict
- Posts: 4778
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: select a face from an image.
Hi Danilo,Danilo wrote:Had some time, so I used the following code to translate to PureBasic: Seeing With OpenCV, Part 2: Finding Faces in ImagesLittle John wrote:Can we access the C++ interface with PureBasic?
DOWNLOAD: OpenCV244_PB510_FaceDetect_Test_001.zip (3,39MB)
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:
