Exemplo n.º 1
0
        private Image <Gray, byte> HaarDetection(string xmlFile, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE haarDetectionTipe, string path)
        {
            var bitmap = new Bitmap("TrainedFaces/downloaded/" + path);

            var image = new Image <Gray, Byte>(bitmap);

            //Face Detector
            MCvAvgComp[][] faces = image.DetectHaarCascade(
                new HaarCascade(xmlFile),
                1.1,
                10,
                haarDetectionTipe,
                new Size(40, 40)
                );


            Image <Gray, byte> newFace = null;

            //Action for each element detected
            foreach (MCvAvgComp f in faces[0])
            {
                newFace = image.Copy(f.rect).Convert <Gray, byte>().Resize(200, 200, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                break;
            }

            return(newFace);
        }
Exemplo n.º 2
0
        public static Rectangle[] Detect(Image <Bgr, Byte> image, string cascadeFile,
                                         double scaleFactor = 1.3, int minNeighbors = 10,
                                         Emgu.CV.CvEnum.HAAR_DETECTION_TYPE detectionType = Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                                         int minSize = 20, int maxSize = 0)
        {
            string cascadeFilePath = CascadeManager.GetCascade(cascadeFile);

            Size minimumSize;

            if (minSize == 0)
            {
                minimumSize = Size.Empty;
            }
            else
            {
                minimumSize = new Size(minSize, minSize);
            }

            Size maximumSize;

            if (maxSize == 0)
            {
                maximumSize = Size.Empty;
            }
            else
            {
                maximumSize = new Size(maxSize, maxSize);
            }

            if (GpuInvoke.HasCuda)
            {
                using (GpuCascadeClassifier cascade = new GpuCascadeClassifier(cascadeFilePath))
                    using (GpuImage <Bgr, Byte> gpuImage = new GpuImage <Bgr, byte>(image))
                        using (GpuImage <Gray, Byte> gpuGray = gpuImage.Convert <Gray, Byte>())
                        {
                            return(cascade.DetectMultiScale(gpuGray, scaleFactor, minNeighbors, minimumSize));
                        }
            }
            else
            {
                using (HaarCascade cascade = new HaarCascade(cascadeFilePath))
                    using (Image <Gray, Byte> gray = image.Convert <Gray, Byte>())
                    {
                        gray._EqualizeHist();

                        MCvAvgComp[] detected = cascade.Detect(gray,
                                                               scaleFactor, minNeighbors,
                                                               detectionType,
                                                               minimumSize, maximumSize);

                        return((from x in detected
                                select x.rect).ToArray());
                    }
            }
        }
Exemplo n.º 3
0
 private Image <Gray, byte> HaarDetectionAlt2(Emgu.CV.CvEnum.HAAR_DETECTION_TYPE haarDetectionTipe, string path)
 {
     return(HaarDetection("haarcascade_frontalface_alt2.xml", haarDetectionTipe, path));
 }