title: How to determine if an object stopped moving or left the frame
body: <p>Every tutorial, sample or blog I have read show various ways to track a moving object in a frame, as long as it is <em>moving</em>. This has become ubiquitous. </p>
  
  <p>What I have been trying to figure out is how to <strong><em>determine if the object stopped moving or actually left the frame</em></strong>. When using background separation, when an object stops moving it becomes part of the foreground and as such "disappears". It "reappears" when it moves again. As far as I can tell the same behavior exists when an object leaves the frame, it just "disappears". For example the following code fragment demonstrates this:</p>
  
  <pre><code>**BackgroundSubtractorMOG2 _fgDetector = new BackgroundSubtractorMOG2();
  CvBlobDetector _blobDetector = new CvBlobDetector();
  CvTracks _tracker = new CvTracks();
  CvBlobs _blobs = new CvBlobs();**
  
  private int FindAndTrack()
  {
      CvInvoke.GaussianBlur(_analyzeMat, _smoothedFrame, new System.Drawing.Size(3, 3), 1); 
  
      #region use the BG/FG detector to find the forground mask
  
      _fgDetector.Apply(_smoothedFrame, _foregroundMask);
  
      #endregion use the BG/FG detector to find the forground mask
  
      _blobDetector.Detect(_foregroundMask.ToImage&lt;Gray, byte&gt;(), _blobs);
      _blobs.FilterByArea(_minimumAreaValue, int.MaxValue);
  
      _tracker.Update(_blobs, 0.01 * _scaleValue, 1, 5);
      return _tracker.Count;
  }
  </code></pre>
  
  <p>I am no longer sure that background separation may be the answer.</p>
  
  <p>What would give a definitive indication of a object leaving the frame?</p>
  
  <p>Thanks,
  Doug</p>