title: How can I make openCV Backgroundsubtraction KNN algorithm last longer, tracking a foregound object which is not moving
body: <p>I am trying to substract this building brick. <a href="https://i.stack.imgur.com/slQ4F.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/slQ4F.jpg" alt="orange building brick"></a>
  .</p>
  
  <p>For that I am using the KNN algorithm provided by opencv 3.0.
  To initialize the background model I am using 40 frames without the brick.</p>
  
  <p>All in all it works pretty well.
  (Brick with Shadow)
  <a href="https://i.stack.imgur.com/kmWZ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kmWZ2.png" alt="enter image description here"></a></p>
  
  <p>The only problem is that the algorithm starts loosing the brick around Frame 58 </p>
  
  <p>(Image shows frame 62)</p>
  
  <p><a href="https://i.stack.imgur.com/3x0Ub.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3x0Ub.png" alt="enter image description here"></a></p>
  
  <p>After frame 64 I get only black images. I know this wouldn't happen if the brick would move, but unfortunatly there are long sequences where it doesn`t.</p>
  
  <p>Does somebody know a solution to this?</p>
  
  <p>PS: I tried playing around with the history Paramer of </p>
  
  <pre><code>cv::createBackgroundSubtractorKNN(int history,double Threshold, bool detectShadows= true)
  </code></pre>
  
  <p>But there is no difference between <code>history = 500 or history = 500000</code></p>