title: Mat, training data in ml opencv
body: <p>I'm beginner in opencv. I have not gotten main concepts of opencv in details. </p>
  
  <p>So maybe my code it's too dumb;</p>
  
  <p>Out of my curiosity I want to try machine learning functions like a KNN, ANN.
  I have the set of images with size 28*28 pixels. I want to do train cassifier for digit recognition. So first I need to assemble train set and train classes; </p>
  
  <pre><code>    Mat train_data = Mat(rows, cols, CV_32FC1);
      Mat train_classes = Mat(rows, 1, CV_32SC1);
      Mat img = imread(image);
      Mat float_data(1, cols, CV_32FC1);
      img.convertTo(float_data, CV_32FC1);
  </code></pre>
  
  <p>How to fill train_data with float_data ?
  I thought It was smth like this:</p>
  
  <pre><code>for (int i = 0; i &lt; train_data.rows; ++i) 
  {
      ... // image is a string which contains next image path
      image = imread(image);
      img.convertTo(float_data, CV_32FC1);
      for( int x = 0; x &lt; train_data.cols; x++ ){
        train_data.at&lt;float&gt; (i, x) = float_data.at&lt;float&gt;( x);; 
      }
   }
  
   KNearest knn;
   knn.train(train_data, train_classes);
  </code></pre>
  
  <p>but it's of course doesn't work . . .
  Please, tell me how to do it right. Or at least suggest the books for dummies :)</p>