title: opencv accessing color element of CV_32FC3 BGR cv::Mat
body: <p>i have a kind of problem. i've seen some more similar question but i can't find a solution.</p>
  
  <p>my problem is that i have a CV_32FC3 cv::Mat, where values are stored in range between 0 and 255, let's call it S. </p>
  
  <p>I have to create a matrix, called P, where store BGR values of all pixel.</p>
  
  <p>So P should have as rows number the total element of S pixel, and as cols number the number of channels (3).</p>
  
  <p>this is what i've tried to do:</p>
  
  <pre><code>int n_pixels = S.cols * S.rows;
  p = Mat::zeros(n_pixels, 3, CV_32FC1);
  
  for(int i=0; i&lt;n_pixels; i++) {
      Scalar pixel = S.at&lt;Scalar&gt;(i); // i've tried also Vec3f, Point3_, etc..
  
      p.at&lt;float&gt;(i,0) = pixel[0];
      p.at&lt;float&gt;(i,1) = pixel[1];
      p.at&lt;float&gt;(i,2) = pixel[2];
  }
  </code></pre>
  
  <p>i've also tried low level c-api data access like this:</p>
  
  <pre><code>for(int i=0; i&lt;selection.rows; i++) {
      p.at&lt;float&gt;(i,0) = S.ptr&lt;float&gt;(i)[0];
      p.at&lt;float&gt;(i,1) = S.ptr&lt;float&gt;(i)[1];
      p.at&lt;float&gt;(i,2) = S.ptr&lt;float&gt;(i)[2];
  
  }
  </code></pre>
  
  <p>and also splitting channels (but splitted channels have type CV_8U so i think it is wrong):</p>
  
  <pre><code>vector&lt;Mat&gt; bgr;
  cv::split(S, bgr);
  
  for(int i=0; i&lt;n_pixels; i++) {
      p.at&lt;float&gt;(i,0) = bgr[0].data[i];
      p.at&lt;float&gt;(i,1) = bgr[1].data[i];
      p.at&lt;float&gt;(i,2) = bgr[2].data[i];
  }
  </code></pre>
  
  <p>but every time i get really weird result if coutting the pixels, like:</p>
  
  <pre><code>172.2042 0.0000 0.0000 
  2771.1414 0.0000 0.0000 
  2939505920.0000 3.3468 0.0000 
  3079446986752.0000 0.0129 0.0000 
  192669347217408.0000 0.8367 0.0000 
  51956177323392237568.0000 16301891256320.0000 0.0509 
  58314208864123224064.0000 3.3945 0.0029 
  180449.1406 0.0000 0.0000 
  0.6531 0.0000 0.0000 
  0.0100 0.0000 0.0000 
  2.7373 0.0000 0.0000 
  10957.3184 0.0000 0.0000 
  739729604608.0000 3.3778 0.0000 
  0.0000 0.0000 0.0000 
  0.0000 0.0000 0.0000 
  0.0000 0.0000 0.0000 
  0.0000 0.0000 0.0000 
  </code></pre>
  
  <p>and, in some cases also segfault..</p>
  
  <p>any delucidations? how to resolve it? why my trials are wrong?</p>
  
  <p>EDIT: i think the problems are data types conversion</p>