【发布时间】:2011-09-22 12:27:54
【问题描述】:
此时我有一个函数,它从我的相机界面调用图像。此图像随后会保存到硬盘驱动器并显示在 Windows 窗体 GUI 中。
相机接口内部返回图像的函数如下: 高度和宽度都是属于相机接口类的整数。在本例中,它们被设置为 800x600。
public Image<Bgr,byte> QueryFrame()
{
Image<Bgr, byte> temp;
lock (key)
{
using (Capture cap = new Capture())
{
cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, height);
cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, width);
temp = cap.QueryFrame().Copy();
}
}
return temp;
}
多次调用该函数首先表明捕获帧花费了相对较长的时间,从而将程序锁定了几秒钟而无法使用。然后,在 Debug with Visual C# 2010 中运行程序时捕获了几帧后,弹出 vshost.exe 的 windows 错误:
Faulting application DashboardGUI.vshost.exe, version 10.0.30319.1, time stamp 0x4ba2084b, faulting module MSVCR90.dll, version 9.0.30729.6161, time stamp 0x4dace5b9, exception code 0xc0000005, fault offset 0x00024682, process id 0xe78, application start time 0x01cc792086025f01.
然后我继续发布应用程序并从可执行文件运行它并收到错误:
Application: DashboardGUI.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitializationException
Stack:
at Emgu.CV.CvInvoke.cvReleaseCapture(IntPtr ByRef)
at Emgu.CV.Capture.DisposeObject()
at Emgu.Util.DisposableObject.Finalize()
但是我也让它与 Emgu.CV.CvInvoke.cvCreateCameraCapture(Int32) 抛出相同的异常。
是什么导致了这些问题?如何避免它们?有没有什么方法可以比现在更快地捕获帧(当它不崩溃时)?
【问题讨论】:
标签: c# computer-vision emgucv