简体   繁体   中英

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!!

henne959, I am also fairly new to emgu c# - but have been around the opencv realm a little. First thing to realize is that it evolves. Names change. So keep an open mind. I recently played around with face detection a la emgu c# (3.0) and found the tutorial you mentioned. The CascadeClassifier class is there. But, I found the HAAR detector (that I wanted to use) manifest as an extension to that class: DetectMultiScale

Among the links I noted while researching this topic - these two were among my favorite (sorry - I don't have the rep points to include more links) http://fewtutorials.bravesites.com/entries/emgu-cv-c/level-3c---how-to-improve-face-detection http://blogs.interknowlogy.com/2013/10/21/face-detection-for-net-using-emgucv/

These two lines of code will probably help you tie the pieces together

CascadeClassifier _cascadeClassifier = new CascadeClassifier(@"C:\OPENCV_3.0.0\opencv\build\etc\haarcascades\" + "haarcascade_frontalface_alt2.xml");

Rectangle RectFaces = _cascadeClassifier.DetectMultiScale(tMat, 1.03, 1, new Size(tMat.Width/13, tMat.Height/13), new Size((int)((double)tMat.Width/1.05), (int)((double)tMat.Width / 1.05)));

Hope this helps!

要将Mat转换为Image<>使用ToString()方法并使用CascadeClassifier而不是HaarCascade

Emgu.CV is an open source project. You can find it on sourceforce.com . They also have git repository here . You can clone it in your computer.

This repository also includes sample projects (in Emgu.CV.Example folder).

ps I can't tell you exactly which class you need, however you can check the sample project called FaceDetection . They are using CascadeClassifier and CudaCascadeClassifier classes. Hope this helps.

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 );
    }
}

I have been searching for a EmguCV 3.0 solution for 3 days now and finally found this post specifically targeting the topic. I hope this helps someone else out there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM