title: OpenCV PCA question
body: <p>I'm trying to create a PCA model in OpenCV to hold pixel coordinates. As an experiment I have two sets of pixel coordinates that maps out two approximate circles. Each set of coordiantes has 48 x,y pairs. I was experimenting with the following code which reads the coordinates from a file and stores them in a Mat structure. However, I don't think it is right and PCA in openCV seems very poorly covered on the Internet. </p>
  
  <pre><code>    Mat m(2, 48, CV_32FC2); // matrix with 2 rows of 48 cols of floats held in two channels
  
  pFile = fopen("data.txt", "r");
  
  for (int i=0; i&lt;48; i++){
      int x, y;
      fscanf(pFile, "%d%c%c%d%c", &amp;x, &amp;c, &amp;c, &amp;y, &amp;c);
  
      m.at&lt;Vec2f&gt;( 0 , i )[0] = (float)x; // store x in row 0, col i in channel 0
      m.at&lt;Vec2f&gt;( 0 , i )[1] = (float)y; // store y in row 0, col i in channel 1
  
  }
  
  for (int i=0; i&lt;48; i++){
      int x, y;
      fscanf(pFile, "%d%c%c%d%c", &amp;x, &amp;c, &amp;c, &amp;y, &amp;c);
  
      m.at&lt;Vec2f&gt;( 1 , i )[0] = (float)x; // store x in row 1, col i in channel 0
      m.at&lt;Vec2f&gt;( 1 , i )[1] = (float)y; // store y in row 1, col i in channel 1
  
  }
  
  PCA pca(m, Mat(), CV_PCA_DATA_AS_ROW, 2); // 2 principle components??? Not sure what to put here e.g. is it 2 for two data sets or 48 for number of elements?
  
      for (int i=0; i&lt;48; i++){
   float x = pca.mean.at&lt;Vec2f&gt;(i,0)[0]; //get average x
       float y = pca.mean.at&lt;Vec2f&gt;(i,0)[1]; //get average y
       printf("\n x=%f, y=%f", x, y);
  }
  </code></pre>
  
  <p>However, this crashes when creating the pca object. I know this is a very basic question but I am a bit lost and was hoping that someone could get me started with pca in open cv.</p>