关于人脸识别和检测的慢速视频

时间:2019-04-16 10:46:54

标签: emgucv

我正在使用EMGUCV进行面部检测和识别,使用的版本为“ 3.3.0”,而使用的IP摄像机为CP Plus子弹型摄像机。

我可以进行检测和识别,但是识别后的实时视频非常慢,比实际流落后10-15秒。不确定代码中是否包含任何内容。

下面是我到目前为止完成的代码。不确定如何加快速度。

Form_Load()
{
    _videoCapture = new VideoCapture("rtsp://uname:pwd@19.18.1.40:554");
    Application.Idle += new EventHandler(FrameGrabber_Standard);
} 
private void FrameGrabber_Standard(object sender, EventArgs e)
        {
            try
            {
                Image<Bgr, Byte> currentFrame = _videoCapture.QueryFrame().ToImage<Bgr, Byte>().Resize(640, 480, Inter.Cubic);
                if (currentFrame != null)
                {
                    Image<Gray, byte> gray_frame = currentFrame.Convert<Gray, Byte>();
                    List<Rectangle> listFaces = new List<Rectangle>();
                    detectfacensobj.DetectFaces(currentFrame, listFaces); //the actual face detection happens here
                    foreach (Rectangle face in listFaces)
                    {
                        faceResult = currentFrame.Convert<Bgr, byte>();
                        if (Eigenfaces.IsTrained)
                        {
                            Image<Gray, byte> grayFaceResult = faceResult.Convert<Gray, byte>();
                            var result = Eigenfaces.eigenFaceRecognizer.Predict(grayFaceResult.Resize(200, 200, Inter.Cubic));
                            if (result.Label != -1)
                            {
                                CvInvoke.PutText(currentFrame, Eigenfaces.eigenlabels[result.Label], new System.Drawing.Point(face.X - 2, face.Y - 2), FontFace.HersheyComplex, 1.0, new Bgr(Color.Orange).MCvScalar);
                            }

                        }

                        currentFrame.Draw(face, new Bgr(Color.Red), 2);
                    }
                    captureImageBox.Image = currentFrame.Bitmap;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
public bool DetectFaces(IInputArray image, List<Rectangle> listfaces)
        {
            bool isDetect = false;

            try
            {
                using (UMat grayImage = new UMat())
                {
                    CvInvoke.CvtColor(image, grayImage, ColorConversion.Bgr2Gray);
                    CvInvoke.EqualizeHist(grayImage, grayImage);

                    Rectangle[] facesDetected = faceCascadeClass.DetectMultiScale(grayImage, 1.1, 3, new Size(20, 20));
                    if (facesDetected.Length == 0)
                    {
                        isDetect = false;
                    }
                    else
                    {
                        isDetect = true;
                        listfaces.AddRange(facesDetected);
                    }
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Erro" + ex.Message);
            }
            return isDetect;
        }
```````````````````

0 个答案:

没有答案