emguCV 3.1 - face detection

怎甘沉沦 提交于 2019-11-30 23:31:47

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!

user6544739

To convert Mat into Image<> use ToString() method and use CascadeClassifier instead of HaarCascade.

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

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).

p.s. 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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!