예제 #1
0
        public void Process(FaceDetectionResult result)
        {
            if (!_classifier.IsTrained)
            {
                _classifier.Retrain();
            }

            using (var grayframe = new Image <Gray, byte>(result.Face).Resize(100, 100, Emgu.CV.CvEnum.Inter.Cubic))
            {
                if (_classifier.Recognise(grayframe))
                {
                    _mediator.SendMessageAsync(this, new FaceRecognitionResult
                    {
                        Label  = _classifier.GetEigenLabel,
                        Image  = result.Image,
                        Result = FaceRecognitionResultType.Recognized
                    }, FaceRecognitionResultType.Recognized);
                }
                else
                {
                    _mediator.SendMessageAsync(this,
                                               new FaceRecognitionResult
                    {
                        Image  = result.Image,
                        Result = FaceRecognitionResultType.Unrecognized
                    }, FaceRecognitionResultType.Unrecognized);
                }
            }
        }
예제 #2
0
        public void Process(Bitmap picture)
        {
            using (var grayframe = new Image <Gray, byte>(picture))
            {
                var result = new FaceDetectionResult
                {
                    Result = FaceDetectionResultType.FaceNotFound,
                };

                var frontfaces = _frontFaceCascadeClassifier.DetectMultiScale(grayframe, 1.1, 10, Size.Empty);
                if (frontfaces.Length > 0)
                {
                    result.Result = FaceDetectionResultType.OneFaceFound;
                    result.Image  = picture;
                    result.Face   = picture.Clone(frontfaces[0], picture.PixelFormat);
                    Debug.WriteLine("front face found");
                    _mediator.SendMessageAsync(this, result, result.Result);
                    return;
                }

                var leftProfile = _profileCascadeClassifier.DetectMultiScale(grayframe, 1.1, 10, Size.Empty);
                if (leftProfile.Length > 0)
                {
                    result.Result = FaceDetectionResultType.OneFaceFound;
                    result.Image  = picture;
                    result.Face   = picture.Clone(leftProfile[0], picture.PixelFormat);
                    Debug.WriteLine("left profile found");
                    _mediator.SendMessageAsync(this, result, result.Result);
                    return;
                }
                picture.RotateFlip(RotateFlipType.Rotate180FlipY);
                var rotatedFrame = new Image <Gray, byte>(picture);
                var rightProfile = _profileCascadeClassifier.DetectMultiScale(rotatedFrame, 1.1, 10, Size.Empty);
                rotatedFrame.Dispose();
                if (rightProfile.Length > 0)
                {
                    result.Result = FaceDetectionResultType.OneFaceFound;
                    result.Image  = picture;
                    result.Face   = picture.Clone(rightProfile[0], picture.PixelFormat);
                }

                Debug.WriteLine(result.Result == FaceDetectionResultType.FaceNotFound ? "face not found" : "right profile found");
                _mediator.SendMessageAsync(this, result, result.Result);
            }
        }