emguCV 3.1 - face detection
Solution 1
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 );
}
}
Solution 2
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!
Solution 3
To convert Mat
into Image<>
use ToString()
method and use CascadeClassifier
instead of HaarCascade
.
Solution 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.
henne959
I'm an engineer for refridgeration and air condition who works in industrial engineering. I'm coding for fun but I hope I can use it at work soon.
Updated on July 09, 2022Comments
-
henne959 almost 2 years
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 classImage<>
. The classImage<>
hasn't worked withcapture.QueryFrame();
But when I come to face detection, the tutorial says I should use the classesCascadeClassifier
andDetectHaarCascade
.CascadeClassifier
is accepted butDetectHaarCascade
is not known. In my 5-hour!! search I just found out, that DetectHaarCascade is obsolete but didn't find any methods replacing it exeptHaarCascade.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 over 8 yearsThanks! This is the thing I looked for! The link between detecthaarcascade and detectmultiscale was missing in my search... :-D