title: Feature tracking using optical flow
body: <p>I found a <a href="https://stackoverflow.com/questions/9701276/opencv-tracking-using-optical-flow/9702540#comment13031247_9702540">similar question</a> in the forum. But the answer in there does not answer my question.</p>
  
  <ul>
  <li><p>If I do feature detection (goodFeaturesToTrack) <strong>only once on the first image</strong>, and then use optical flow (calcOpticalFlowPyrLK) to track these features, the problem is: only the features detected on the first image can be tracked. When these features go beyond of the image, there would be no features to track. </p></li>
  <li><p>If I do feature detection <strong>for every new image</strong>, the feature tracking is not stable, because the feature detected last time may not be detected this time.</p></li>
  </ul>
  
  <p>I am using optical flow for 3D reconstruction.  So I'm not interested in tracking what features, instead, I only care whether features in the field of view can be tracked stably. To summarize, <strong>my question is</strong>: how can I use optical flow to track old features, and in the meantime add new image features that come into the field of view and remove old features that go beyond the field of view?</p>