Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emguCV 3.1 - face detection

I'm new to OpenCV/EmguCV in C#. I tried a tutorial (http://fewtutorials.bravesites.com/entries/emgu-cv-c/level-3---live-face-detection) and the video captureing with the webcam was easy. Now my problem: The tutorial was written for EmguCV 2.x. I'm using EmguCV 3.1 (I like to use the newest). Therefor I used the class Mat instead of the class Image<>. The class Image<> hasn't worked with capture.QueryFrame(); But when I come to face detection, the tutorial says I should use the classes CascadeClassifier and DetectHaarCascade. CascadeClassifier is accepted but DetectHaarCascade is not known. In my 5-hour!! search I just found out, that DetectHaarCascade is obsolete but didn't find any methods replacing it exept HaarCascade.Detect() which is also not known.

I have following assamblies:

using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Emgu.CV.CvEnum;

So, please help me: What is the replacement for DetectHaarCascade and how do I use it? Is there any tutorial for EmguCV 3.1?

Thanks!!

like image 787
henne959 Avatar asked Oct 17 '25 08:10

henne959


1 Answers

Get a look at the example for face detection / DetectFace.cs:

Important are:

using Emgu.CV;
using Emgu.CV.Structure;

and:

IInputArray image, 
String faceFileName, String eyeFileName,
List<Rectangle> faces
using( CascadeClassifier face = new CascadeClassifier( faceFileName ) )
{
    using( UMat ugray = new UMat() )
    {
        CvInvoke.CvtColor( image, ugray, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray );

        //normalizes brightness and increases contrast of the image
        CvInvoke.EqualizeHist( ugray, ugray );

        //Detect the faces  from the gray scale image and store the locations as rectangle                   
        Rectangle[] facesDetected = face.DetectMultiScale(
           ugray, 1.1, 10, new Size( 20, 20 ) );

        faces.AddRange( facesDetected );
    }
}
like image 137
Ryugeist Avatar answered Oct 19 '25 22:10

Ryugeist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!