title: OpenCV persistent object tracking and hysteresis strategy
body: <p>I'm building an object tracking API for my team. </p>
  
  <p>My code will recognize foreground objects in the camera scene. Over time, it will call methods for <code>addObject(id, pos)</code>, <code>updateObject(id, newPos)</code>, and <code>removeObject(id)</code> on instances that implement my listener interface. These are post frame-processing events -- so they might occur 30 times a second.</p>
  
  <p>How can I make sure that objects don't flicker in and out of existence? I need to give objects a minimum lifetime. If an object disappears for one frame and reappears in the same spot in the next frame with a new ID, that is also undesired flickering.</p>
  
  <hr>
  
  <p>(My thoughts so far) I have thought about using an object mask accumulator as a basis for  instantiation. I imagine a grayscale image, where candidate regions for objects would be intensified in the accumulator each frame, then as soon as an object region exceeds a threshold, it gets instantiated and we call the <code>addObject(id, pos)</code> method. Now, the problem with this is, an object can hover around the threshold in the accumulator and can still exhibit flickery behavior.  So then, I would add some constant value to the object region as soon as it is instantiated so that it would have a lifetime in the accumulator. This constant would be subtracted when the region crosses below the accumulator threshold.  </p>