Emgu CV Capture IP 摄像机人脸检测问题
Issue with EmguCV Capture IP cam Face Detection
我正在使用 EmguCV 2.2.1.1150 连接网络摄像头工作正常,但是当我使用 RTSP 协议连接网络摄像头时,它只工作了几分钟并抛出异常,但使用网络摄像头时没有抛出异常。
我有这个代码:
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);
}
}
为什么会这样?
好吧,我必须将 Emgu CV 2.2.1.1150 更新到 3.0.0.2157,使用那个 Emgu CV 版本就可以了。
我正在使用 EmguCV 2.2.1.1150 连接网络摄像头工作正常,但是当我使用 RTSP 协议连接网络摄像头时,它只工作了几分钟并抛出异常,但使用网络摄像头时没有抛出异常。
我有这个代码:
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);
}
}
为什么会这样?
好吧,我必须将 Emgu CV 2.2.1.1150 更新到 3.0.0.2157,使用那个 Emgu CV 版本就可以了。