This tutorial has already been posted on the other sites, since maybe few have only knew about that site then I'll have to post it here. This tutorial has also been explain in the Emgu CV website that refers in this link:
http://www.emgu.com/wiki/index.php/Face_detection
in which that link refers also in this link
http://friism.com/webcam-face-detection-in-c-using-emgu-cv
Notes in order to run this example:
*Create a Windows Form Application
*Add a PictureBox and a Timer (and Enable it)
*Run it on a x86 system
*Be sure you have the OpenCV relevant dlls (included with the Emgu CV download) in the folder where you code executes.
*Adjust the path to find the Haarcascade xml (last line of the code)
1.)You don’t have to install OpenCV, but instead have to copy the relevant dlls (included with the Emgu CV download) to the folder where you code executes.
2.)Open CV and X64 are not friends. If you’re running X64 Windows (and unless you are up to recompiling OpenCV) you have to make sure your app is compiled to X86, instead of the usual “Any CPU”.
3.)Remember to add PictureBox as per the original tutorial.
Here’s sample code:
using System;
using System.Windows.Forms;
using System.Drawing;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;
namespace opencvtut
{
public partial class Form1 : Form
{
private Capture cap;
private HaarCascade haar;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
using (Image nextFrame = cap.QueryFrame())
{
if (nextFrame != null)
{
// there's only one channel (greyscale), hence the zero index
//var faces = nextFrame.DetectHaarCascade(haar)[0];
Image grayframe = nextFrame.Convert();
var faces =
grayframe.DetectHaarCascade(
haar, 1.4, 4,
HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new Size
(nextFrame
.Width/8, nextFrame
.Height/8)
)[0];
foreach (var face in faces)
{
nextFrame
.Draw(face
.rect,
new Bgr
(0,
double.MaxValue,
0),
3);
}
pictureBox1.Image = nextFrame.ToBitmap();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
// passing 0 gets zeroth webcam
// adjust path to find your xml
"..\\..\\..\\..\\lib\\haarcascade_frontalface_alt2.xml");
}
}
}
Good luck my fellow programmers..