EmguCV Capture IP cam人脸检测问题

时间:2017-07-21 21:47:42

标签: c# webcam emgucv face-detection ip-camera

我正在使用EmguCV连接网络摄像头2.2.1.1150工作正常,但是当我使用RTSP协议连接IP摄像头只能工作几分钟并抛出异常,但是网络摄像头没有抛出异常。

我有这段代码:

private void btnDetectar_Click(object sender, EventArgs e)
{
    //grabber = new Capture(@"rtsp://user:pass@address:554/cam/realmonitor?channel=1&subtype=01?tcp"); // IP CAMERA
    grabber = new Capture(); // WEBCAM

    // Inicia la función FrameGrabber
    Application.Idle += new EventHandler(FrameGrabber);
    btnDetectar.Enabled = false;
}


void FrameGrabber(object sender, EventArgs e)
{
    try
    {
        // Obtiene el "frame" actual del dispositivo de captura
        currentFrame = grabber.QueryFrame().Resize(704, 480, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

        // Se convierte a escala de grises
        Image<Gray, byte> gray = currentFrame.Convert<Gray, byte>();

        // Detector facial
        MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
              face,
              1.2,
              10,
              Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
              new Size(gray.Width / 6, gray.Height / 6));

        // Acción para cada elemento detectado
        foreach (MCvAvgComp faces in facesDetected[0])
        {
            result = currentFrame.Copy(faces.rect).Convert<Gray, byte>().Resize(200, 200, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
            // dibuja rectangulo en rostro detectado                     
            currentFrame.Draw(faces.rect, new Bgr(Color.Red), 3);
        }

        picUser.Image = currentFrame.ToBitmap();

    }
    catch (Exception a)
    {
        String timeStamp = DateTime.Now.ToString();
        MessageBox.Show(" Hora: " + timeStamp + "\n Error: " + a.Message + "\n Stacktrace: " + a.StackTrace + "\n", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

为什么会这样?

1 个答案:

答案 0 :(得分:0)

好吧,我必须将Emgu CV 2.2.1.1150更新为3.0.0.2157,只需使用该Emgu CV版本。