using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Emgu.CV; using Emgu.Util; using Emgu.CV.Structure; using Emgu.CV.CvEnum; namespace capture { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Capture cap; private HaarCascade haar; private void Form1_Load(object sender, EventArgs e) { // passing 0 gets zeroth webcam cap = new Capture(0); // adjust path to find your xml haar = new HaarCascade("haarcascade_mcs_mouth.xml"); } private void timer1_Tick(object sender, EventArgs e) { using (Image<Bgr, byte> nextFrame = cap.QueryFrame()) { if (nextFrame != null) { // there's only one channel (greyscale), hence the zero index //var faces = nextFrame.DetectHaarCascade(haar)[0]; Image<Gray, byte> grayframe = nextFrame.Convert<Gray, byte>(); 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) { //int x = face.rect.Height; //nextFrame.Draw(face.rect, new Bgr(100, double.MaxValue, 0), 3); //label1.Text = face.rect.Top.ToString(); label1.Text = face.rect.Height.ToString(); } pictureBox1.Image = nextFrame.ToBitmap(); } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)