gpt4 book ai didi

C# - 应用程序在连接网络摄像机后挂起

转载 作者:太空宇宙 更新时间:2023-11-03 22:32:01 25 4
gpt4 key购买 nike

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

我正在使用 Emgu.CV Library抓取帧并将其显示在图片控件中。

我已经尝试使用函数 QueryFrame() 显示视频的以下代码.

用于连接网络摄像机 Capture capture = new Capture(URL);

用于抓取帧 Image<Bgr, Byte> ImageFrame = capture.QueryFrame();

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

谁能告诉我为什么会这样,我该如何处理?

提前谢谢你。

最佳答案

抱歉延迟,但我提供了一个适用于多个公共(public) IP 摄像机的示例。它将需要用您当前的版本替换 EMGU 引用,目标构建目录应设置为“EMGU Version\bin”,或者将其解压缩到示例文件夹。

http://sourceforge.net/projects/emguexample/files/Capture/CameraCapture%20Public%20IP.zip/download

它没有使用旧的 QueryFrame() 方法,而是使用 RetrieveBgrFrame() 方法。它工作得相当好,我没有出现空异常。但是,如果您将 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());
}
}

干杯

克里斯

关于C# - 应用程序在连接网络摄像机后挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21693264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com