我有2台IP摄像机,它们是不同的型号,都来自同一制造商。让我们称之为 Cam1 和 Cam2 。我想通过网络地址从这些摄像机中检索帧,但是存在一些问题。
的段1: 的
使用frame = capture.RetrieveBgrFrame();
框架时始终 null 。
使用frame = capture.QueryFrame();
框架时确定。
Cam2 (与我的电脑在同一网络中):
使用frame = capture.RetrieveBgrFrame();
框架时始终 null 。
使用frame = capture.QueryFrame();
时, WinForm 被冻结,计算机(i3 3,3GHz,6GB RAM)冻结。
两个流地址都可以。我试图用VLC和OpenCV C ++平台打开它们。
这里可能有什么问题?
以下是代码:
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
using Emgu.CV.UI;
namespace IPcamera
{
public partial class Form1 : Form
{
private Capture capture;
private Image<Bgr, Byte> frame;
public Form1()
{
InitializeComponent();
try
{
capture = new Capture(camera_address);
}
catch (NullReferenceException exception)
{
MessageBox.Show(exception.Message);
}
if (capture != null)
{
Application.Idle += ProcessFrame;
}
}
void ProcessFrame(object sender, EventArgs e)
{
frame = capture.RetrieveBgrFrame();
if (frame != null)
{
pictureBox1.Image = frame.ToBitmap();
}
}
}
}
答案 0 :(得分:0)
我通常不使用IP摄像机,但我怀疑它们在初始化时不会开始拍摄图像。 RetrieveBgrFrame()返回摄像机拍摄的las图像,因此如果我是正确的,RetrieveBgrFrame()将返回null,因为摄像机本身没有拍摄图像。尝试将ProcessFrame处理程序添加到摄像头事件capture.ImageGrabbed而不是Application.Idle,并检查它是否被调用。
关于冻结,如果是“低fps”冻结,可能是由于摄像机速度慢,或者试图通过慢速总线发送大图像。如果它永远冻结,请检查没有任何其他应用程序可以使用该相机并释放资源(您是在cam2之前尝试cam1还是在新运行中尝试使用cam2?)
答案 1 :(得分:0)
你可以替换
吗? Application.Idle += ProcessFrame;
与
capture.ImageGrabbed += ProcessFrame;
然后,RetrieveBgrFrame()方法可以重新启动框架。这就是我通常这样做的方式,我没有遇到任何问题。您可能需要使用invoke将图像分配给pictureBox1.Image。
pictureBox1.Invoke((MethodInvoker) (() => pictureBox1.Image = frame.ToBitmap()));