title: cv::goodFeaturesToTrack doesn't return any features
body: <p>I'm trying to use <a href="http://opencv.willowgarage.com/documentation/cpp/structural_analysis_and_shape_descriptors.html#cv-pointpolygontest" rel="nofollow noreferrer"><code>cv::calcOpticalFlowPyrLK</code></a> but sometimes an internal assertion in that function fails. The assertion is <code>npoints = prevPtsMat.checkVector(2, CV_32F, true)) &gt;= 0</code>. I'm using OpenCV 2.3.1. The source code for this function is available <a href="http://code.opencv.org/svn/opencv/branches/2.3/opencv/modules/video/src/lkpyramid.cpp" rel="nofollow noreferrer">here</a>.</p>
  
  <p>It's hard to wrap my head around their code, especially because of my limited experience with computer graphics and their lack of comments. Why is this assertion being triggered and what does it say about my problem?</p>
  
  <p><strong>Edit</strong>: I call the function as follows:</p>
  
  <pre><code>cv::calcOpticalFlowPyrLK(curBwFrame, prvFrame, features, newFeatures, trackingStatus, errors);
  </code></pre>
  
  <p>I found out that the <code>features</code> vector, which was obtained by calling <code>cv::goodFeaturesToTrack(curBwFrame, features, 5, 0.2, 0.5, skinMask);</code> with a non-empty mask that appears to be sufficiently big and a valid image, doesn't contain any features. How can this happen?</p>
  
  <p><strong>curBwFrame</strong></p>
  
  <p><img src="https://i.imgur.com/SCuBG.png" alt="curBwFrame"></p>
  
  <p><strong>skinMask</strong></p>
  
  <p><img src="https://i.imgur.com/2RIm0.png" alt="skinMask"></p>
  
  <p>I'm able to reproduce the problem using the following code snippet:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;vector&gt;
  #include &lt;cassert&gt;
  #include &lt;opencv2\opencv.hpp&gt;
  using std::vector;
  using namespace cv;
  
  int main() {
      vector&lt;Point2f&gt; features;
      cv::Mat curBwFrame = imread("curBwFrame.png");
      cv::cvtColor(curBwFrame, curBwFrame, CV_RGB2GRAY);
      imwrite("test.png", curBwFrame);
  
      cv::Mat skinMask = imread("skinMask.png");
      cv::cvtColor(skinMask, skinMask, CV_RGB2GRAY);
      imwrite("test.png", skinMask);
  
      cv::goodFeaturesToTrack(curBwFrame, features, 5, 0.2, 0.5, skinMask);
      assert(features.size() &gt; 0);
  
      return 0;
  }
  </code></pre>