Beispiel #1
0
        private void ProcessFrame(object sender, EventArgs arg)
        {
            if (_capture != null && _capture.Ptr != IntPtr.Zero)
            {
                String rect = "";
                _capture.Retrieve(_frame, 0);

                CvInvoke.CvtColor(_frame, _grayFrame, ColorConversion.Bgr2Gray);

                CvInvoke.PyrDown(_grayFrame, _smallGrayFrame);

                long             detectionTime;
                List <Rectangle> faces = new List <Rectangle>();
                List <Rectangle> eyes  = new List <Rectangle>();

                if (detection)
                {
                    DetectFace.Detect(
                        _frame, "haarcascade_frontalface_default.xml",
                        faces, eyes,
                        out detectionTime);

                    foreach (Rectangle face in faces)
                    {
                        rect = face.ToString();
                        CvInvoke.Rectangle(_grayFrame, face, new Bgr(Color.Red).MCvScalar, 2);
                        CvInvoke.Rectangle(_frame, face, new Bgr(Color.Red).MCvScalar, 2);
                    }
                }


                captureImageBox.Image   = _frame;
                grayscaleImageBox.Image = _grayFrame;
                AppendTextBox(rect, textBox1);
            }
        }
Beispiel #2
0
        }                            // /////////////////////////////////////////////////////////////////////////////////////////////////////////

        private void Run(UMat image) //!!!UMat
        //IImage image;
        //Read the files as an 8-bit Bgr image

        //image = new UMat("lena.jpg", ImreadModes.Color); //UMat version
        //image = new Mat("lena.jpg", ImreadModes.Color); //CPU version

        {
            long             detectionTime;
            List <Rectangle> faces = new List <Rectangle>();
            List <Rectangle> eyes  = new List <Rectangle>();

            //			DetectFace.Detect(
            //			  image, "haarcascade_frontalface_default.xml", "haarcascade_eye.xml",
            //			  faces, eyes, out detectionTime);
            DetectFace.DetectOnlyFace(
                image, "haarcascade_frontalface_default.xml",
                faces, out detectionTime,
                FaceParam.ScaleFactor(txScaleFactor), FaceParam.MinNeighbors(txMinNeighbors), FaceParam.MinObjectSize(txMinObjectSize));

            foreach (Rectangle face in faces)
            {
                CvInvoke.Rectangle(image, face, new Bgr(Color.Red).MCvScalar, 2);
            }
            foreach (Rectangle eye in eyes)
            {
                CvInvoke.Rectangle(image, eye, new Bgr(Color.Blue).MCvScalar, 2);
            }
            double r = gemor.put(faces.Count > 0);

            if (r < 0.4 && (signal == Signal.yes || signal == Signal.nodef))
            {
                signal = Signal.no;
            }
            else if (r > 0.6 && (signal == Signal.no || signal == Signal.nodef))
            {
                signal = Signal.yes;
            }
            string sret = phases.Run(signal, r);
            //lbDbgTimers.Text = sret;
            MCvScalar color = new MCvScalar(255, 0, 255, 0);

            CvInvoke.PutText(image, sret, new Point(2, 25), FontFace.HersheyComplexSmall, 1, color);             //_grayFrame
            if (signal == Signal.nodef && false)
            {
                if (faces.Count > 0)
                {
                    using (InputArray iaImage = image.GetInputArray()) {
                        string sreport = String.Format(
                            "Completed face detection using {0} in {1} milliseconds. Rct={2} x {3} r={4}",
                            (iaImage.Kind == InputArray.Type.CudaGpuMat && CudaInvoke.HasCuda) ? "CUDA" :
                            (iaImage.IsUMat && CvInvoke.UseOpenCL) ? "OpenCL" : "CPU", detectionTime,
                            faces[0].Width, faces[0].Height, r);
                        Console.WriteLine(sreport);
                    }
                }
                else
                {
                    Console.WriteLine(r.ToString());
                }
            }
        }         // ////////////////////////////////////////////////////////////////////////////////////////////////////////////