Detección de ojos y boca desde la cara mediante cascadas de haar.

He extraído los ojos y la boca de la cara, pero quiero extraer emociones de los ojos y la boca. Sin embargo, la boca no se detecta correctamente. Este es mi código.

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(); Image gray = nextFrame.Convert(); Image gray1 = 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]; MCvAvgComp[][] eyes = gray.DetectHaarCascade(eye, 1.1, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20)); gray.ROI = Rectangle.Empty; MCvAvgComp[][] mouthsDetected = gray.DetectHaarCascade(mouth, 1.1, 10, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20)); gray1.ROI = Rectangle.Empty; foreach (MCvAvgComp mouthsnap in mouthsDetected[0]) { Rectangle mouthRect = mouthsnap.rect; // mouthRect.Offset(f.rect.X, f.rect.Y); nextFrame.Draw(mouthRect, new Bgr(Color.Red), 2); detectedmouth = mouthRect; } foreach (MCvAvgComp eyesnap in eyes[0]) { Rectangle eyeRect = eyesnap.rect; // mouthRect.Offset(f.rect.X, f.rect.Y); nextFrame.Draw(eyeRect, new Bgr(Color.Green), 2); } foreach (var face in faces) { nextFrame.Draw(face.rect, new Bgr(Color.LightGreen), 3); facesnap = face.rect; } pictureBox1.Image = nextFrame.ToBitmap(); } } } private void Form1_Load(object sender, EventArgs e) { cap = new Capture(0); // adjust path to find your xml //haar = new HaarCascade("haarcascade_frontalface_alt2.xml"); haar = new HaarCascade("haarcascade_frontalface_alt_tree.xml"); mouth = new HaarCascade("Mouth.xml"); eye = new HaarCascade("haarcascade_eye_tree_eyeglasses.xml"); } private void button1_Click(object sender, EventArgs e) { Image snap = pictureBox1.Image; snap.Save("c:\\snapshot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); pictureBox2.Image = snap; pictureBox3.Image = cropImage(snap,facesnap); pictureBox4.Image = cropImage(snap, detectedmouth); } private static Image cropImage(Image img, Rectangle croparea) { Bitmap bmpImage = new Bitmap(img); Bitmap bmpCrop = bmpImage.Clone(croparea, bmpImage.PixelFormat); return (Image)(bmpCrop); } 

Por favor, ayúdeme en la detección de emociones y una mejor detección de la boca usando c #.

Intentaría buscar una boca en un rectángulo de cara, en lugar de revisar la imagen del agujero.

 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 f in faces) { //draw the face detected in the 0th (gray) channel with blue color image.Draw(f.rect, new Bgr(Color.Blue), 2); //Set the region of interest on the faces gray.ROI = f.rect; var mouthsDetected = gray.DetectHaarCascade(mouth, 1.1, 10, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20)); gray.ROI = Rectangle.Empty; foreach (var m in mouthsDetected [0]) { Rectangle mouthRect = m.rect; mouthRect.Offset(f.rect.X, f.rect.Y); image.Draw(mouthRect , new Bgr(Color.Red), 2); } } 

He dividido el área de la cara en 2 rectangularjs superior e inferior … y apliqué el rectángulo inferior a gray.ROI. y funciona … este es el código para ambos rectangularjs …

  int halfheight = facesnap.Height/2; int start = facesnap.X; int start1 = facesnap.Y; Rectangle top = new Rectangle(start,start1,facesnap.Width,halfheight); int start2 = top.Bottom; Rectangle bottom = new Rectangle(start, start2, facesnap.Width, halfheight); nextFrame.Draw(bottom, new Bgr(Color.Yellow), 2); //Set the region of interest on the faces gray.ROI = bottom; MCvAvgComp[][] mouthsDetected = gray.DetectHaarCascade(mouth, 1.1, 10, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20));