private void buscarrosto(Bitmap frame)
        {
            Image <Rgb, Byte> imageCV = new Image <Rgb, byte>(frame);

            Emgu.CV.Mat mat   = imageCV.Mat;
            var         array = new byte[mat.Width * mat.Height * mat.ElementSize];

            mat.CopyTo(array);

            using (Array2D <RgbPixel> image = Dlib.LoadImageData <RgbPixel>(array, (uint)mat.Height, (uint)mat.Width, (uint)(mat.Width * mat.ElementSize)))
            {
                using (FrontalFaceDetector fd = Dlib.GetFrontalFaceDetector())

                {
                    var faces = fd.Operator(image);
                    foreach (DlibDotNet.Rectangle face in faces)
                    {
                        FullObjectDetection shape          = _ShapePredictor.Detect(image, face);
                        ChipDetails         faceChipDetail = Dlib.GetFaceChipDetails(shape, 150, 0.25);
                        Array2D <RgbPixel>  faceChip       = Dlib.ExtractImageChip <RgbPixel>(image, faceChipDetail);
                        Bitmap bitmap1 = faceChip.ToBitmap <RgbPixel>();
                        MainWindow.main.Statusa1 = bitmap1;
                        Dlib.DrawRectangle(image, face, color: new RgbPixel(0, 255, 255), thickness: 4);
                    }
                }
                frame = image.ToBitmap <RgbPixel>();
                MainWindow.main.Statusa = frame;
            }
        }
Beispiel #2
0
        private void ProcessFrame(object sender, EventArgs e)
        {
            Stopwatch SW = new Stopwatch();

            SW.Start();

            try
            {
                Mat temp = new Mat();
                _capture.Read(temp);

                var array = new byte[temp.Width * temp.Height * temp.ElementSize];
                temp.CopyTo(array);

                Array2D <RgbPixel> cimg = Dlib.LoadImageData <RgbPixel>(array, (uint)temp.Height, (uint)temp.Width, (uint)(temp.Width * temp.ElementSize));

                Rectangle[] faces = detector.Operator(cimg);

                if (faces.Any())
                {
                    FullObjectDetection        det    = poseModel.Detect(cimg, faces[0]);
                    List <FullObjectDetection> shapes = new List <FullObjectDetection>();
                    shapes.Add(det);
                    FullObjectDetection       shape = shapes[0];
                    ImageWindow.OverlayLine[] lines = Dlib.RenderFaceDetections(shapes);

                    if (chbShowLineOnly.Checked)
                    {
                        cimg = new Array2D <RgbPixel>(cimg.Rows, cimg.Columns);
                    }

                    foreach (var line in lines)
                    {
                        Dlib.DrawLine(cimg, line.Point1, line.Point2, new RgbPixel {
                            Green = 255
                        });
                    }

                    pictureBoxImage.Image?.Dispose();
                    pictureBoxImage.Image = cimg.ToBitmap();

                    foreach (var line in lines)
                    {
                        line.Dispose();
                    }

                    for (uint i = 0; i < shape.Parts; i++)
                    {
                        landmarkPoint.Insert((int)i, new Point(shape.GetPart(i).X, shape.GetPart(i).Y));
                    }

                    GetFacialBlendShape();

                    foreach (var s in shapes)
                    {
                        s.Dispose();
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.StackTrace);
            }

            SW.Stop();
            Debug.WriteLine(string.Format("FPS: {0}", 1000 / SW.ElapsedMilliseconds));
        }