【问题标题】:C#: AccessViolationException from EmguCV when trying to retrieve framesC#:尝试检索帧时来自 EmguCV 的 AccessViolationException
【发布时间】:2017-06-19 06:32:58
【问题描述】:

我正在尝试使用 EmguCV 库显示来自 3 个不同摄像机的实时流。 通过将相应的索引传递给构造函数,使用 VideoCapture 类连接摄像机。

VideoCapture _capture1 = new VideoCapture(0);
VideoCapture _capture2 = new VideoCapture(1);
VideoCapture _capture3 = new VideoCapture(2);

每个实例都订阅“ImageGrabbed”事件并尝试在事件处理程序中检索帧。

_capture1.ImageGrabbed += ProcessFrame;

事件处理程序:

    private void ProcessFrame(object sender, EventArgs arg)
    {
        if (_capture1!= null && _capture1.Ptr != IntPtr.Zero)
        {
            Mat _frame = new Mat();
            _capture1.Retrieve(_frame, 0);
        }
    }

但偶尔,_capture.Retrieve() 方法会产生 AccessViolationException。

异常详情:

System.AccessViolationException 未处理。试图阅读或 写受保护的内存。这通常表明其他内存 已损坏。

谁能解释一下是什么导致了这个异常?

【问题讨论】:

  • 如果您包含异常详细信息,对我们查找问题会更有帮助
  • 异常表示“System.AccessViolationException 未处理。试图读取或写入受保护的内存。这通常表明其他内存已损坏。”

标签: c# emgucv access-violation


【解决方案1】:

我通过将 VideoCapture.API.DShow 传递给 VideoCapture 的构造函数而不是使用默认的 VideoCapture.API.Any 值来解决它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多