title: OpenCV's calcOpticalFlowPyrLK throws exception
body: <p>I have been trying to form a small optical flow example with OpenCV for a while now.  Everything works except the function call calcOpticalFlowPyrLK, which prints the following failed assertion in the console window:</p>
  
  <blockquote>
    <p>OpenCV Error: Assertion failed (mytype == typ0 || (CV_MAT_CN(mytype) == CV_MAT_CV(type0) &amp;&amp; ((1 &lt;&lt; type0) &amp; fixedDepthMask) != 0)) in unknown function, file ......\src\opencv\modules\core\src\matrix.cpp, line 1421</p>
  </blockquote>
  
  <p>The video that I'm parsing is separated into 300 images, labelled as "caml00000.jpeg", "caml00001.jpeg", ..., "caml00299.jpeg".  Here is the code I wrote:</p>
  
  <pre><code>#include &lt;cv.h&gt;
  #include "opencv2/highgui/highgui.hpp"
  
  using namespace cv;
  using namespace std;
  
  int main( int argc, char** argv ){
  
      char buff[100];
      int numFrames=300;
      char fileFormat[]="images/caml%05d.jpeg";
  
      string winname="Test Window";
  
      vector&lt;Mat&gt; imgVec(numFrames);
  
      auto itrImg=begin(imgVec);
      auto itrEnd=end(imgVec);
      vector&lt;Point2f&gt; featuresPrevious;
      vector&lt;Point2f&gt; featuresCurrent;
  
      namedWindow( winname, CV_WINDOW_AUTOSIZE );
      int fileNum=0;
      while(itrImg!=itrEnd){
          Mat&amp; imgRef=*itrImg; //get this frame's Mat from the vector iterator
  
          //Calculate the name of the file;
          sprintf(buff,fileFormat,fileNum);
          string fileName=buff;
          //string fileName="kitty.jpg"; //attempted using a static picture as well
          cout &lt;&lt; fileName &lt;&lt; endl;
  
          Mat cImage=imread(fileName, CV_LOAD_IMAGE_GRAYSCALE);
          cImage.convertTo(imgRef, CV_8U); //also tried CV_8UC1
          featuresPrevious=std::move(featuresCurrent);
          goodFeaturesToTrack(imgRef,featuresCurrent,30, 0.01, 30); //calculate the features for use in next iteration
          if(!imgRef.data){ //this never executes, so there isn't a problem reading the files
              cout &lt;&lt; "File I/O Problem!" &lt;&lt; endl;
              getchar();
              return 1;
          }
  
          if(fileNum&gt;0){
              Mat&amp; lastImgRef=*(itrImg-1); //get the last frame's image
              vector&lt;Point2f&gt; featuresNextPos;
              vector&lt;char&gt; featuresFound;
              vector&lt;int&gt; err;
              calcOpticalFlowPyrLK(lastImgRef,imgRef,featuresPrevious,featuresNextPos,featuresFound,err); //problem line 
              //Draw lines connecting previous position and current position
              for(size_t i=0; i&lt;featuresNextPos.size(); i++){
                  if(featuresFound[i]){
                      line(imgRef,featuresPrevious[i],featuresNextPos[i],Scalar(0,0,255));
                  }
              }
          }
  
          imshow(winname, imgRef);
  
          waitKey(1000/60); //not perfect, but it'll do
  
          ++itrImg;
          ++fileNum;
      }
  
      waitKey(0);
      return 0;
  }
  </code></pre>
  
  <p>The only thing I've read about this exception is that it is caused when Mats are in different formats, however I've tried reading a static image (see code above regarding "kitty.jpg") and I still get the same failed assertion.  Any ideas?</p>