title: cvCalcOpticalFlowPyrLK input image size
body: <p>When using <code>cvCalcOpticalFlowPyrLK</code>, generated pyramids seem wrong for some input image size. I cannot find in documentation any reference to good input image size. Nevertheless it finds points. Does anyone know how this happens and how to fix this?</p>
  
  <pre><code>#include &lt;opencv/highgui.h&gt;
  #include &lt;opencv/cv.h&gt;
  #include &lt;iostream&gt;
  
  #define SHOW_IMAGE(image) { \
    cvNamedWindow(#image, CV_WINDOW_AUTOSIZE); \
    cvShowImage(#image, image); \
  }
  
  const CvScalar COLOR_GREEN = { { 0.0, 255.0, 0.0, 255.0 } };
  const CvScalar COLOR_RED = { { 255.0, 0.0, 0.0, 255.0 } };
  
  void drawPoint(IplImage* image, const float x, const float y, const CvScalar&amp; color) {
    cvCircle(image, cvPoint(x, y), 3, color, -1, 8);
  }
  
  void drawPoints(IplImage* image, const CvPoint2D32f* points, const char* status, int count) {
    for (int i = 0; i != count; ++i) {
      if (status[i] == 1) {
        drawPoint(image, points[i].x, points[i].y, COLOR_GREEN);
      } else {
        drawPoint(image, points[i].x, points[i].y, COLOR_RED);
      }
    }
  }
  
  using namespace std;
  
  int main( int argc, char** argv ) {
    /* load samples */
    IplImage* src0 = cvLoadImage( "test0.png" );
    IplImage* src1 = cvLoadImage( "test1.png" );
    CvSize size = cvSize(src0-&gt;width, src0-&gt;height);
    /* allocate grey images and convert to grey */
    IplImage* prev = cvCreateImage(size, 8, 1);
    cvCvtColor(src0, prev, CV_RGB2GRAY);
    IplImage* curr = cvCreateImage(size, 8, 1);
    cvCvtColor(src1, curr, CV_RGB2GRAY);
    /* allocate pyramids */
    IplImage* prevPyr = cvCreateImage(size, 8, 1);
    IplImage* currPyr = cvCreateImage(size, 8, 1);
    /* set previous features */
    const CvPoint2D32f prevFeatures[] = {{133, 133}, {364, 133}, {364, 322}, {133, 322}};
    /* allocate current features */
    CvPoint2D32f currFeatures[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
    int count = 4;
    CvSize winSize = cvSize(20, 20);
    int level = 3;
    char status[4];
    CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03);
    int flags = 0;
    cvCalcOpticalFlowPyrLK(
      /* previous image    */prev
      /* current image     */, curr
      /* previous pyramid  */, prevPyr
      /* current pyramid   */, currPyr
      /* previous features */, prevFeatures
      /* current features  */, currFeatures
      /* features count    */, count
      /* win_size          */, winSize
      /* level             */, level
      /* status            */, status
      /* track error       */, 0
      /* criteria          */, criteria
      /* flags             */, flags);
    drawPoints(src0, prevFeatures, status, count);
    drawPoints(src1, currFeatures, status, count);
    SHOW_IMAGE(src0);
    SHOW_IMAGE(src1);
    SHOW_IMAGE(currPyr);
    SHOW_IMAGE(prevPyr);
    /* wait any key */
    while (cvWaitKey(1) == -1);
    return 0;
  }
  </code></pre>
  
  <p>(if using gcc you can compile and run this with <code>g++ pyr.cpp -o pyr -lcv -lcvaux &amp;&amp; ./pyr</code>)</p>
  
  <p><strong>Screenshot with 640x480 image</strong>
  <img src="https://i.stack.imgur.com/WNEDJ.png" alt="Screenshot with 640x480 image"></p>
  
  <p><strong>Screenshot with 631x480 image</strong>
  <img src="https://i.stack.imgur.com/i58de.png" alt="Screenshot with 631x480"></p>