Exemple #1
0
        public FindFacesResponse FindFacesUnmanaged(Bitmap bitmap)
        {
            FindFacesResponse response = new FindFacesResponse();

            Image<Bgr, Byte> image = new Image<Bgr, Byte>(bitmap);
            Image<Gray, Byte> gray = image.Convert<Gray, byte>();
            MCvAvgComp[][] faces = gray.DetectHaarCascade(this.unmanagedHaarFace, 1.1, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new System.Drawing.Size(20, 20));

            response.TotalFaces = faces[0].Length;
            response.FacesWithEyes = 0;
            response.Faces = new List<FaceStructure>();

            foreach (var f in faces[0])
            {
                FaceStructure face = new FaceStructure();
                face.Face = f.rect;
                face.Eyes = new List<Rectangle>();

                gray.ROI = f.rect;
                MCvAvgComp[][] eyes = gray.DetectHaarCascade(this.unmanagedHaarEyes, 1.1, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new System.Drawing.Size(20, 20));
                gray.ROI = Rectangle.Empty;

                int ignore = eyes[0].Length > 0 ? ++ response.FacesWithEyes : 0;
                foreach (var eye in eyes[0])
                {
                    Rectangle eyeRect = new Rectangle();
                    eyeRect.X = f.rect.X + eye.rect.X;
                    eyeRect.Y = f.rect.Y + eye.rect.Y;
                    eyeRect.Width = eye.rect.Width;
                    eyeRect.Height = eye.rect.Height;
                    //eye.rect.Offset(f.rect.X, f.rect.Y);
                    face.Eyes.Add(eyeRect);
                }

                response.Faces.Add(face);
            }

            return response;
        }
Exemple #2
0
 public void MarkFaces(Bitmap bitmap, FindFacesResponse faces)
 {
     Graphics g = Graphics.FromImage(bitmap);
     if (faces.Faces != null)
     {
         foreach (var f in faces.Faces)
         {
             g.DrawRectangle(new Pen(Brushes.Red), f.Face);
             if (f.Eyes.Count > 0)
             {
                 g.DrawRectangles(new Pen(Brushes.Yellow), f.Eyes.ToArray());
             }
         }
     }
     g.Dispose();
 }
Exemple #3
0
        public FindFacesResponse FindFacesManaged(Bitmap bitmap)
        {
            FindFacesResponse response = new FindFacesResponse();
            var seq = openCV.Net.FaceDetector.DetectFaces(bitmap, managedHaarFace, new Size(20, 20), 1.1);
            response.TotalFaces = seq.Count;
            response.FacesWithEyes = 0;
            response.Faces = new List<FaceStructure>();

            foreach (var f in seq)
            {
                FaceStructure face = new FaceStructure();
                face.Face = f.Rectangle;
                face.Eyes = new List<Rectangle>();

                Bitmap eyeImage = ExtractFaceImage(bitmap, f);
                var eyeSeq = openCV.Net.FaceDetector.DetectFaces(eyeImage, managedHaarEyes);
                int ignore = eyeSeq.Count > 0 ? ++response.FacesWithEyes : 0;

                foreach (var eye in eyeSeq)
                {
                    Rectangle eyeRect = new Rectangle();
                    eyeRect.X = f.Rectangle.X + eye.Rectangle.X;
                    eyeRect.Y = f.Rectangle.Y + eye.Rectangle.Y;
                    eyeRect.Width = eye.Rectangle.Width;
                    eyeRect.Height = eye.Rectangle.Height;
                    face.Eyes.Add(eyeRect);
                }

                response.Faces.Add(face);
            }

            return response;
        }