我正在使用Emgucv从视频文件中捕获帧这是我的代码
private void Frame(object sender, EventArgs arg)
{
try
{
timesbetweenframes++;
Image<Bgr, Byte> frame = FrameExtractor.QueryFrame();
if (timesbetweenframes == 10 || timesbetweenframes == 0)
{
if (frame != null)
{
Bgr min = new Bgr(65, 65, 65);
Bgr threshold = new Bgr(128, 128, 128);
Image<Bgr, Byte> Frame2 = frame;
//Noise Removal
frame._SmoothGaussian(5);
VideoBox.Image = Frame2;
Bgr drawColor = new Bgr(Color.Blue);
using (Image<Gray, byte> gray = frame.Convert<Gray, Byte>())
{
TextExtract.Recognize(gray);
Tesseract.Charactor[] charactors = TextExtract.GetCharactors();
foreach (Tesseract.Charactor c in charactors)
{
Frame2.Draw(c.Region, drawColor, 1);
}
}
cptrdImage.Image = frame;
String text = TextExtract.GetText();
//removal of noise in this section
Tags.Items.Add(text);
WriteData(text, fileName,frame);
fileName++;
}
else
{
MessageBox.Show("Done!");
FrameExtractor = null;
InProgress = false;
timer1.Elapsed -= Frame;
}
timesbetweenframes = 0;
}
}
帧函数被添加到timer事件中,这会在每500 ms后自动触发帧函数并提取每10帧。现在问题是在调用queryframe()函数后,程序崩溃并出现错误: “0x7777f7a99的限制在0x00000000处引用了内存。一段时间后内存无法读取。”
我是以错误的方式使用它,还是有其他方法可以做到这一点而不会出现此错误。
答案 0 :(得分:0)
也许时间(500毫秒)太短了?
我会将此函数附加到Application.Idle事件,如果需要更多延迟,则Thread.Sleep(neededTime - consumeTimeByFrameFunction) 这样可以消除可能的时间问题。