如何清除通过跟踪处理的每个帧?因为现在在我的应用程序中,它会继续增加帧数,消耗大量内存并使我的计算机冻结。
谢谢。
修改
使用3种方法使用camshift算法开始跟踪,更新色调图像,手跟踪器和跟踪手。 1.将图像转换为hsv,获取色调通道颜色,为色调通道做直方图 2.做背投影 3.做camshift - > meanshift算法
public void HandTracker(Image<Bgr, Byte> ImageFrame, Rectangle currentrect) { hsv = Emgu.CV.CvInvoke.cvCreateImage(new Size(ImageFrame.Width, ImageFrame.Height), IPL_DEPTH.IPL_DEPTH_8U, 3); hue = Emgu.CV.CvInvoke.cvCreateImage(new Size(ImageFrame.Width, ImageFrame.Height), IPL_DEPTH.IPL_DEPTH_8U, 1); mask = Emgu.CV.CvInvoke.cvCreateImage(new Size(ImageFrame.Width, ImageFrame.Height), IPL_DEPTH.IPL_DEPTH_8U, 1); backproject = Emgu.CV.CvInvoke.cvCreateImage(new Size(ImageFrame.Width, ImageFrame.Height), IPL_DEPTH.IPL_DEPTH_8U, 1); histogram = new DenseHistogram(30, new RangeF(0, 180)); previoushand = currentrect; UpdateHueImage(ImageFrame); //show how many frame detected frame = frame + 1; label_1.Text = frame.ToString(); float vmax = 0; float vmin = 0; float scale = 0; x = new IntPtr[1] { hue }; Emgu.CV.CvInvoke.cvSetImageROI(hue, currentrect); Emgu.CV.CvInvoke.cvSetImageROI(mask, currentrect); Emgu.CV.CvInvoke.cvCalcHist(x, histogram, false, mask); Emgu.CV.CvInvoke.cvGetMinMaxHistValue(histogram, ref vmin, ref vmax, null, null); if (vmax != 0) { scale = 255 / vmax; } Emgu.CV.CvInvoke.cvConvertScale(histogram.MCvHistogram.bins, histogram.MCvHistogram.bins, scale, 0); Emgu.CV.CvInvoke.cvResetImageROI(hue); Emgu.CV.CvInvoke.cvResetImageROI(mask); //if (ImageFrame != null) ImageFrame.Dispose(); Debug.WriteLine("hand tracker done!"); } public Rectangle TrackHand(Image<Bgr, Byte> ImageFrame) { MCvConnectedComp components = new MCvConnectedComp(); UpdateHueImage(ImageFrame); //show how many frame detected frame = frame + 1; label_2.Text = frame.ToString(); IntPtr[] x = { hue }; Emgu.CV.CvInvoke.cvCalcBackProject(x, backproject, histogram); Emgu.CV.CvInvoke.cvAnd(backproject, mask, backproject, IntPtr.Zero); Emgu.CV.CvInvoke.cvCamShift(backproject, previoushand, new MCvTermCriteria(10, 1), out components, out handcomp); previoushand = components.rect; ImageFrame.Draw(previoushand, new Bgr(Color.Black), 2); Debug.WriteLine("Track hand done!"); return currenthand; } private void UpdateHueImage(Image<Bgr, Byte> currentrect) { Emgu.CV.CvInvoke.cvCvtColor(currentrect, hsv, COLOR_CONVERSION.CV_BGR2HSV); int vmin = 65; int vmax = 256; int smin = 55; Emgu.CV.CvInvoke.cvInRangeS(hsv, new MCvScalar(0, smin, Math.Min(vmin, vmax), 0), new MCvScalar(180, 256, Math.Max(vmin, vmax), 0), mask); Emgu.CV.CvInvoke.cvSplit(hsv, hue, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); Debug.WriteLine("UpdateHueImage done!"); }
这是我的camshift跟踪代码,我发现它消耗了太多内存,并且在检测到800 ++帧后我的电脑会冻结。我如何删除已处理的缓存ImageFrame?
答案 0 :(得分:0)
在处理完图像后调用Dispose()
方法。这将释放消耗内存的非托管IplImage结构。
答案 1 :(得分:0)
您需要的是: https://github.com/dajuric/accord-net-extensions
检查快速模板匹配样本,粒子过滤器样本(手部跟踪)。 适合保存历史的类称为历史。