title: Open Cv fisherfaces
body: <p>I have this problem,</p>
  
  <p>when i run with vs2010 (debug) (open cv 2.4.0) facerec_demo.cpp gaves me the program this error</p>
  
  <blockquote>
    <p>OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows   can not be changed) in unknown function, file ......\src\opencv\modul es\core>\src\matrix.cpp, line 801</p>
  </blockquote>
  
  <p>This error derives me to this line in facerec.cpp<br>
  <strong>(Fisherfaces::train(InputArray src, InputArray _lbls)</strong></p>
  
  <pre><code>Mat data = asRowMatrix(src, CV_64FC1); &lt;-- this gets a exeption, not handled.
  </code></pre>
  
  <p>and a i use at pgm img database and this is my original *facerec_demo.cpp* file</p>
  
  <pre><code>#include "stdafx.h" 
  #include &lt;opencv2/opencv.hpp&gt;
  
  
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  
  using namespace cv;
  using namespace std;
  
  
  vector&lt;string&gt; split_at_commas(const string&amp; row)
  {
    vector&lt;string&gt; res;
    istringstream buf(row);
    string s;
    while (getline(buf, s, ';'))
      res.push_back(s);
    return res;
  }
  
  Mat toGrayscale(InputArray _src) {
      Mat src = _src.getMat();
      // only allow one channel
      if(src.channels() != 1)
          CV_Error(CV_StsBadArg, "Only Matrices with one channel are supported");
      // create and return normalized image
      Mat dst;
      cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1);
      return dst;
  }
  
  void read_csv(const string&amp; filename, vector&lt;Mat&gt;&amp; images, vector&lt;int&gt;&amp; labels, char separator = ';') {
      //std::ifstream file(filename.c_str(), ifstream::in);
      std::ifstream file(_T("D:\\Users\\PC ACER\\Documents\\mycsv4.csv"));
      if (!file)
          throw std::exception();
      string line="", path="", classlabel="";
      while (getline(file, line)) {
          //vector&lt;string&gt; values = split_at_commas(line);
          stringstream liness(line);
          getline(liness, path, ';');
          getline(liness, classlabel);
          images.push_back(imread(path, 0));
          labels.push_back(atoi(classlabel.c_str()));
      }
  }
  
  int main(int argc, const char *argv[]) {
      // check for command line arguments
      if (argc != 2) {
          cout &lt;&lt; "usage: " &lt;&lt; argv[0] &lt;&lt; " &lt;csv.ext&gt;" &lt;&lt; endl;
          exit(1);
      }
      // path to your CSV
      string fn_csv = string(argv[1]);
      // images and corresponding labels
      vector&lt;Mat&gt; images;
      vector&lt;int&gt; labels;
      // read in the data
      try {
          read_csv(fn_csv, images, labels);
      } catch (exception&amp;) {
          cerr &lt;&lt; "Error opening file \"" &lt;&lt; fn_csv &lt;&lt; "\"." &lt;&lt; endl;
          exit(1);
      }
      // get width and height
      //int width = images[0].cols;
      int height = images[0].rows;
      // get test instances
      Mat testSample = images[images.size() - 1];
      int testLabel = labels[labels.size() - 1];
      // ... and delete last element
      images.pop_back();
      labels.pop_back();
      // build the Fisherfaces model
      Ptr&lt;FaceRecognizer&gt; model = createFisherFaceRecognizer();
      model-&gt;train(images, labels);
      // test model
      int predicted = model-&gt;predict(testSample);
      cout &lt;&lt; "predicted class = " &lt;&lt; predicted &lt;&lt; endl;
      cout &lt;&lt; "actual class = " &lt;&lt; testLabel &lt;&lt; endl;
      // get the eigenvectors
      Mat W = model-&gt;eigenvectors();
      // show first 10 fisherfaces
      for (int i = 0; i &lt; min(10, W.cols); i++) {
          // get eigenvector #i
          Mat ev = W.col(i).clone();
      // reshape to original size AND normalize between [0...255]
      Mat grayscale = toGrayscale(ev.reshape(1, height));
          // show image (with Jet colormap)
      Mat cgrayscale;
          applyColorMap(grayscale, cgrayscale, COLORMAP_JET);
          imshow(format("%d", i), cgrayscale);
      }
      waitKey(0);
      return 0;
  }
  </code></pre>