在将视频导入项目时无法分配足够的内存

时间:2015-12-12 13:27:23

标签: c# memory-management emgucv

我正在用EmguCv和C#编写一个程序来检测视频流中的某些模式。起初我正在尝试将视频导入到项目中,但几秒钟后,程序冻结并且不再加载。

我真的不知道,但我认为 可能因为我在导入视频时出错了,最重要的是因为程序使用了14秒后2 GB的RAM

enter image description here

要导入视频并将其显示到GUI,我使用以下代码:

private void timer1_Tick(object sender, EventArgs e) 
{
     Orginal.Image = _capture.QueryFrame();         
}

private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
    _capture = new Capture(openFileDialog1.FileName.ToString());
}

private void button2_Click(object sender, EventArgs e)//Import-Button
{
    openFileDialog1.ShowDialog();
    string _FilePath = openFileDialog1.FileName.ToString();
    textBox1.Text = _FilePath;
}

private void button1_Click(object sender, EventArgs e) //Start-Button
{
    My_Time.Interval = 1000 / FPS;
    My_Time.Tick += new EventHandler(timer1_Tick);
    My_Time.Start();
    _capture = new Capture(openFileDialog1.FileName.ToString());
}

这是导入视频的正确方法,还是有更好的方式?

抛出异常会读取以下内容:

  

Emgu.CV.dll中的Emgu.CV.Util.CvException(" OpenCV:无法分配   6220800字节")

1 个答案:

答案 0 :(得分:1)

您正在抓取的每张图片都有内存泄漏

Orginal.Image = _capture.QueryFrame(); 

我不知道你的计时器滴答毫秒,但如果你每25毫秒获得一个6MB的图像,你每秒得到150MB,在14秒内得到2GB的内存分配。

只需下载一个经典示例来播放/录制视频文件并根据您的需要执行模式检测。 http://www.emgu.com/wiki/index.php/Video_Files