Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-连接IP摄像头后应用程序挂起_C#_Opencv_Emgucv - Fatal编程技术网

C#-连接IP摄像头后应用程序挂起

C#-连接IP摄像头后应用程序挂起,c#,opencv,emgucv,C#,Opencv,Emgucv,我正在开发一个应用程序,使用网络摄像头和IpCamera显示视频。 对于IpCamera,它会显示视频流一段时间,但之后它会停止流式传输,应用程序会挂起 我使用抓取帧并在图片控件中显示它 我使用函数QueryFrame()尝试了以下视频显示代码 用于连接Ip摄像头 Capture-Capture=新的捕获(URL) 用于抓取框架 Image-ImageFrame=capture.QueryFrame() 一段时间后,QueryFrame()提供null值,应用程序挂起 有谁能告诉我为什么会发生这

我正在开发一个应用程序,使用网络摄像头和IpCamera显示视频。 对于
IpCamera
,它会显示视频流一段时间,但之后它会停止流式传输,应用程序会挂起

我使用抓取帧并在图片控件中显示它

我使用函数
QueryFrame()
尝试了以下视频显示代码

用于连接Ip摄像头
Capture-Capture=新的捕获(URL)

用于抓取框架
Image-ImageFrame=capture.QueryFrame()

一段时间后,
QueryFrame()
提供
null
值,应用程序挂起

有谁能告诉我为什么会发生这种情况,我如何处理


提前谢谢。

很抱歉延迟,但我提供了一个可与多个公共IP摄像头配合使用的示例。它需要用当前版本替换EMGU引用,并且目标构建目录应设置为“EMGU version\bin”,或者将其提取到examples文件夹

它使用RetrieveBgrFrame()方法,而不是使用较旧的QueryFrame()方法。它运行得相当好,我没有任何空异常。但是,如果您确实使用如下内容替换ProcessFrame()方法

private void ProcessFrame(object sender, EventArgs arg)
{
    //If you want to access the image data the use the following method call
    //Image<Bgr, Byte> frame = new Image<Bgr,byte>(_capture.RetrieveBgrFrame().ToBitmap());

    if (RetrieveBgrFrame.Checked)
    {
        Image<Bgr, Byte> frame = _capture.RetrieveBgrFrame();
        //because we are using an autosize picturebox we need to do a thread safe update
        if(frame!=null) DisplayImage(frame.ToBitmap());
    }
    else if (RetrieveGrayFrame.Checked)
    {
        Image<Gray, Byte> frame = _capture.RetrieveGrayFrame();
        //because we are using an autosize picturebox we need to do a thread safe update
        if (frame != null) DisplayImage(frame.ToBitmap());
    }
}
private void ProcessFrame(对象发送方,事件args arg)
{
//如果要访问图像数据,请使用以下方法调用
//图像帧=新图像(_capture.RetrieveBgrFrame().ToBitmap());
if(RetrieveBgrFrame.Checked)
{
图像帧=_capture.RetrieveBgrFrame();
//因为我们使用的是自动调整大小的picturebox,所以需要执行线程安全更新
如果(frame!=null)显示图像(frame.ToBitmap());
}
else if(RetrieveGrayFrame.Checked)
{
图像帧=_capture.RetrieveGrayFrame();
//因为我们使用的是自动调整大小的picturebox,所以需要执行线程安全更新
如果(frame!=null)显示图像(frame.ToBitmap());
}
}
干杯


Chris

应用程序挂起时报告的错误是什么?如果是你的代码,你是否有可以提供更多细节的堆栈跟踪?我已经编辑了这个问题。但到目前为止还没有显示任何错误。您是否在if之后对ImageFrame执行任何操作?如果是,您希望在if(ImageFrame!=null)语句中包含它。否则,try{}catch(nullexception ex){}可以解决这个问题,但是如果可能的话,我建议不要这样做。Cheers@Chris我的代码在
try catch
块中,但我在一次匆忙中键入的同一个错误没有异常“NullReferenceException”如果不使用catch(exception ex)应该可以工作,并查看抛出的异常类型。但是如果不是,你能发布导致问题的代码,这样我就可以正确地调试它了。干杯感谢您的回答,但请点击
\u capture=new capture(URL)
它正在抛出错误
System.TypeInitializationException未处理Emgu.CV.Dll
很抱歉这些库是用于x64系统的,如果这是您正在使用的Emgu版本,请将它们替换为x86库,并确保相应地设置了项目的平台目标