-2

I'am connecting a Webcam with EmguCV 2.2.1.1150 works fine, but when I connect an IP cam using RTSP protocol works just for a few minutes and throws exception, but with Webcam no throws exception.

I have this code:

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);
    }
}

Why is this happening?

Bender Bending
  • 729
  • 8
  • 25
Leinad
  • 111
  • 10
  • 2
    Do you think that maybe the text of the exception contains a clue? – Blorgbeard Jul 21 '17 at 22:03
  • Hora: 21/07/2017 05:06:56 p. m. Error: Object reference not set to an instance of an object. Stacktrace: en MultiFaceRec.FrmPrincipal.FrameGrabber(Object sender, EventArgs e) en c:\FaceRecProOV\MainForm.cs:línea 115 (this line "currentFrame = grabber.QueryFrame().Resize(704, 480, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);" ) – Leinad Jul 21 '17 at 22:08
  • Well, start with reading/understanding [this](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) question. Then you'll either solve it, or you can ask a more narrowly defined question. – Blorgbeard Jul 21 '17 at 23:25
  • Still no work.but thank you. – Leinad Jul 25 '17 at 13:16

1 Answers1

0

Well, I had to update Emgu CV 2.2.1.1150 to 3.0.0.2157, just works using that Emgu CV version.

Leinad
  • 111
  • 10