emguCV 3.1 - face detection

为君一笑 提交于 2019-11-30 19:31:37

问题


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


回答1:


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!




回答2:


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




回答3:


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



回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/35394522/emgucv-3-1-face-detection

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