Beispiel #1
0
        public CountFacesResponse CountFacesUnmanaged(Bitmap bitmap)
        {
            CountFacesResponse response = new CountFacesResponse();
            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, 3, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DEFAULT, new System.Drawing.Size(20,20));

            response.TotalFaces = faces[0].Length;
            response.FacesWithEyes = 0;

            foreach (var f in faces[0])
            {
                gray.ROI = f.rect;
                MCvAvgComp[][] eyes = gray.DetectHaarCascade(this.unmanagedHaarEyes, 1.1, 3, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DEFAULT, new System.Drawing.Size(20,20));
                gray.ROI = Rectangle.Empty;
                if (eyes[0].Length > 0)
                    response.FacesWithEyes++;
            }

            return response;
        }
Beispiel #2
0
        public CountFacesResponse CountFacesManaged(Bitmap bitmap)
        {
            CountFacesResponse response = new CountFacesResponse();
            var seq = openCV.Net.FaceDetector.DetectFaces(bitmap, managedHaarFace, new Size(20, 20), 1.1);
            response.TotalFaces = seq.Count;
            response.FacesWithEyes = 0;

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

            return response;
        }