title: How to fill an array of Vec3b
body: <p>I am working with images in C++ with OpenCV.</p>
  
  <p>I wrote code with an uchar array of two dimensions where I can read pixel values of an image, uploaded with imread in grayscale using <code>.at&lt; uchar&gt;(i,j)</code>.</p>
  
  <p>However I would like to do the same thing for color images. Since I know that to access the pixels values I now need <code>.at&lt; Vec3b&gt;(i,j)[0]</code>, <code>.at&lt; Vec3b&gt;(i,j)[1]</code> and <code>.at&lt; Vec3b&gt;(i,j)[2]</code>, I made a similar <code>Vec3b</code> 2d arrays.</p>
  
  <p>But I don't know how to fill this array with the pixel values. It has to be a 2D array.</p>
  
  <p>I tried:</p>
  
  <pre><code>array[width][height].val[0]=img.at&lt; Vec3b&gt;(i,j)[0]
  </code></pre>
  
  <p>but that didn't work.</p>
  
  <p>Didn't find an answer on the OpenCV doc or here neither.</p>
  
  <p>Anybody has an idea?</p>
  
  <p>I've included some of my code. I need an array because I already have my whole algorithm working, using an array, for the images in grayscale with only one channel.</p>
  
  <p>The grayscale code is like that:</p>
  
  <pre><code>for(int i=0;i&lt;height;i++){
      for(int j=0;j&lt;width;j++){
          image_data[i*width+j]=all_images[nb_image-1].at&lt; uchar&gt;(i,j);
      }
  }
  </code></pre>
  
  <p>Where I read from:  </p>
  
  <pre><code>std::vector&lt; cv::Mat&gt; all_images
  </code></pre>
  
  <p>each image (I have a long sequence), retrieves the pixel values in the uchar array <code>image_data</code>, and processes them.</p>
  
  <p>I want now to do the same but for RGB images, and I can't manage to read the data pixel of each channel and put them in an array.</p>
  
  <p>This time image_data is a Vec3b array, and the code I'm trying looks like this:</p>
  
  <pre><code>for(int i=0;i&lt;height;i++){
      for(int j=0;j&lt;width;j++){
          image_data[0][i*width+j]=all_images[nb_image-1].at&lt;cv::Vec3b&gt;(i,j)[2];
          image_data[1][i*width+j]=all_images[nb_image-1].at&lt;cv::Vec3b&gt;(i,j)[1];
          image_data[2][i*width+j]=all_images[nb_image-1].at&lt;cv::Vec3b&gt;(i,j)[0];
      }
  }
  </code></pre>
  
  <p>But this doesn't work, so I am now at loss I don't know how to succeed to fill the <code>image_data</code> array with the values of all three channels, without changing the code structure as this array is then used on my image processing algorithm.</p>