title: How to clear history frames after done tracking in life streaming video?
body: <p>How to clear every frames that have been processed by tracking? because now in my application, it continues to increase the number of frames, consumes a lot of memory and makes my computer freeze.</p>
  
  <p>Thank You.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Start tracking with camshift algorithm with 3 method, update hue image, Hand tracker, and track hand.
  1. convert image to hsv, get hue channel color, do histogram for hue channel
  2. do back projection
  3. do camshift-->meanshift algorithm</p>
  
  <blockquote>
  <pre><code>    public void HandTracker(Image&lt;Bgr, Byte&gt; 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&lt;Bgr, Byte&gt; 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&lt;Bgr, Byte&gt; 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!");
  
      }
  </code></pre>
  </blockquote>
  
  <p>That is my code for camshift tracking, I found that it's consume too much memory and my pc freeze after 800++ frame detected. How I delete cache ImageFrame that already processed?</p>