Example #1
0
        private void faceDetect(ushort j)
        {
            cvsbmp = UtilFn.BitmapImage2Bitmap(images[j]);

            var cascade = new Accord.Vision.Detection.Cascades.FaceHaarCascade();

            var detector = new Accord.Vision.Detection.HaarObjectDetector(cascade, minSize: 50,
                                                                          searchMode: Accord.Vision.Detection.ObjectDetectorSearchMode.Average);


            System.Drawing.Rectangle[] rectangles = detector.ProcessFrame(cvsbmp);
            List <Bitmap> listBitmap = new List <Bitmap>();

            foreach (System.Drawing.Rectangle r in rectangles)
            {
                listBitmap.Add(UtilFn.CropImage(cvsbmp, r.X, r.Y, r.Width, r.Height));
            }

            if (rectangles.Count() == 0)
            {
                imageInfo.Text = "No faces detected!";
            }
            else
            {
                //imagesEdited[j] = (converter.Convert(UtilFn.MergeImages(listBitmap), Type.GetType("BitmapImage"), null, null) as BitmapImage).Clone();
                foreach (var x in listBitmap)
                {
                    imagesEdited.Add((converter.Convert(x, Type.GetType("BitmapImage"), null, null) as BitmapImage).Clone());
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            string[] _files        = System.IO.Directory.GetFiles(@"./", "*.jpg", System.IO.SearchOption.AllDirectories);
            var      cascade_face  = Accord.Vision.Detection.Cascades.FaceHaarCascade.FromXml(@"haarcascade_frontalface.xml");
            var      face_detector = new Accord.Vision.Detection.HaarObjectDetector(cascade_face);

            foreach (var str in _files.Select((value, index) => new { value, index }))
            {
                Console.Write("Processing image {0} of {1}...", _files.Length, 1 + @str.index);
                var    image   = new Bitmap(@str.value);
                var    face    = face_detector.ProcessFrame(image);
                Bitmap cropped = image.Clone(face[0], image.PixelFormat);
                cropped.Save(str.value.Substring(0, str.value.Length - 4) + "_cropped.jpg");
                Console.Write("Done.\r\n");
            }
            Console.Write("Process Finished.");
        }
Example #3
0
        public void FindFace(PictureBox pb)
        {
            AForge.Video.DirectShow.VideoCaptureDevice   FinalVideoSource;
            AForge.Video.DirectShow.FilterInfoCollection VideoCaptuerDevices;
            VideoCaptuerDevices = new AForge.Video.DirectShow.FilterInfoCollection(AForge.Video.DirectShow.FilterCategory.VideoInputDevice);
            FinalVideoSource    = new AForge.Video.DirectShow.VideoCaptureDevice(VideoCaptuerDevices[0].MonikerString);

            FinalVideoSource.NewFrame += new AForge.Video.NewFrameEventHandler((sender, eventArgs) =>
            {
                Bitmap image = (Bitmap)eventArgs.Frame.Clone();
                pb.Image     = image;
            });

            FinalVideoSource.Start();
            FinalVideoSource.NewFrame += new AForge.Video.NewFrameEventHandler((sender, eventArgs) =>
            {
                Bitmap image = (Bitmap)eventArgs.Frame.Clone();
                //görüntüde yüz aranacağı belirtilir.
                Accord.Vision.Detection.Cascades.FaceHaarCascade cascade = new Accord.Vision.Detection.Cascades.FaceHaarCascade();
                //görüntü üzerinde arama yapar. İkinci parametresi minimum arama alanıdır.
                Accord.Vision.Detection.HaarObjectDetector detector = new Accord.Vision.Detection.HaarObjectDetector(cascade, 1);

                detector.SearchMode            = Accord.Vision.Detection.ObjectDetectorSearchMode.Single;
                detector.ScalingFactor         = 1.5f;
                detector.ScalingMode           = Accord.Vision.Detection.ObjectDetectorScalingMode.GreaterToSmaller;
                detector.UseParallelProcessing = true;
                detector.Suppression           = 3;
                Rectangle[] faces = detector.ProcessFrame(image);
                Graphics g        = Graphics.FromImage(image);
                foreach (var face in faces)
                {
                    Pen p = new Pen(Color.Red, 10f);
                    g.DrawRectangle(p, face);
                }
                g.Dispose();

                pb.Image = image;
            });
        }