视频监控中遇到的内存分配失败问题
2013-05-13 21:29
246 查看
这几天在做车流量统计,用的是Emgu,查看Emgu安装文件下的Examples例子,经过修改后,第一次选择视频进行车辆统计的时候没有问题,但是不关闭窗体第二次选择视频进行统计的时候会出现内存分配失败的问题。搜了很多方法还是没有解决。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Emgu.CV; using Emgu.CV.UI; using Emgu.CV.CvEnum; using Emgu.CV.Structure; using Emgu.CV.VideoSurveillance; using System.Diagnostics; using System.Threading; namespace TrafficStatistics { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private static MCvFont _font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);//定义显示的字体 private static Capture cameraCapture; private static BlobTrackerAuto<Bgr> tracker;//定义一个块状的汽车跟踪器 private static FGDetector<Bgr> detector;//定义一个背景建模检测器 private object lockObject = new object(); //用于锁定的对象 private Stopwatch sw = new Stopwatch(); //计时器 // Image<Bgr, Byte> frame;//得到视频文件中的一帧 // bool stop = false; /// <summary> /// 打开视频文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "视频文件|*.avi;*.rmvb;*.rm"; if (dialog.ShowDialog() == DialogResult.OK) { String fileName = dialog.FileName; //cameraCapture = CvInvoke.cvCreateFileCapture(file); try { cameraCapture = new Capture(fileName); //cameraCapture.FlipHorizontal = ! cameraCapture.F } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } detector = new FGDetector<Bgr>(FORGROUND_DETECTOR_TYPE.FGD); tracker = new BlobTrackerAuto<Bgr>(); Application.Idle += ProcessFrame; } void ProcessFrame(object sender, EventArgs e) { using (MemStorage stor = new MemStorage()) //得到视频文件中的一帧 { Image<Bgr, Byte> frame = cameraCapture.QueryFrame(); if (frame != null) { frame._SmoothGaussian(3); //filter out noises:对于当前的图像进行高斯平滑处理过滤噪声 #region use the BG/FG detector to find the forground mask detector.Update(frame);//更新当前图像 Image<Gray, Byte> forgroundMask = detector.ForegroundMask;//得到前景图像 #endregion try { //tracker.Process(frame, forgroundMask);//处理图像产生一种色调掩模,调用这句话会出现内存不足异常 //tracker.Process(frame); tracker.Process(cameraCapture.QuerySmallFrame().PyrUp());//只传入一半的图片进行识别和跟踪 } catch (Exception ex) { MessageBox.Show(ex.Message); } foreach (MCvBlob blob in tracker) { frame.Draw((Rectangle)blob, new Bgr(255.0, 255.0, 255.0), 2); //frame.Draw(blob.ID.ToString(), ref _font, Point.Round(blob.Center), new Bgr(255.0, 255.0, 255.0)); vehicleStatTextBox.Text = blob.ID.ToString();//统计车辆数目 } imageBox1.Image = frame; //tracker.Dispose(); } } } } }
相关文章推荐
- 解决Lunix下的大内存分配运行失败问题---未解决
- 关于C++编程思想151页遇到的内存分配问题
- 启动regionserver失败内存分配不足问题
- 今天遇到一个关于对象和对象方法内存分配的有趣的问题
- Kylin遇到的问题记录--reduce 内存分配不足
- 学习中遇到的问题--关于内存分配异常的问题
- 内存充足时,malloc内存分配失败问题
- C++成员函数的内存分配问题
- 关于jvm内存分配的问题heap size [268435456] not equal to maximum heap size [2147483648],需要修改的jvm配置
- 遇到问题---java获取网络文件大小失败getContentLength()为-1 完整解决方法
- C/C++中结构体内存分配问题
- 频繁分配释放内存导致的性能问题的分析
- VC中结构体内存分配问题透析(“字节对齐”访问数据)
- C++的内存分配问题
- scanf 字符串分配内存问题
- 内存分配问题
- JAVA的内存分配与释放问题
- 内存分配的问题
- //问题:将n个数从小到大排序如果n是奇数输出正中间的数,如果n是偶数,输出中间的两个数(用动态内存分配的方法)
- 内存分配问题与调试机制