Eye and Mouth detection from face using haar-cascades

蹲街弑〆低调 提交于 2019-12-01 14:24:56

I would try to look for a mouth in a face rectangle, instead of checking the hole picture.

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

i have divided face area in 2 rectangles top and bottom..and applied bottom rectangle to gray.ROI. and it works.. this is the code for both rectangles..

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