title: OpenCV cv::Mat 'ones' for multi-channel matrix?
body: <p>When working with 1-channel (e.g. <code>CV_8UC1</code>) Mat objects in OpenCV, this creates a Mat of all ones: <code>cv::Mat img = cv::Mat::ones(x,y,CV_8UC1)</code>.</p>
  
  <p>However, when I use 3-channel images (e.g. <code>CV_8UC3</code>), things get a little more complicated. Doing <code>cv::Mat img = cv::Mat::ones(x,y,CV_8UC3)</code> puts <i>ones</i> into channel 0, but channels 1 and 2 contain <i>zeros</i>. <b>So, how do I use <code>cv::Mat::ones()</code> for multi-channel images?</b></p>
  
  <p>Here's some code that might help you to see what I mean:</p>
  
  <pre><code>void testOnes() {
   int x=2; int y=2; //arbitrary
  
   // 1 channel
   cv::Mat img_C1 = cv::Mat::ones(x,y,CV_8UC1);
   uchar px1 = img_C1.at&lt;uchar&gt;(0,0); //not sure of correct data type for px in 1-channel img
   printf("px of 1-channel img: %d \n", (int)px1); //prints 1
  
   // 3 channels
   cv::Mat img_C3 = cv::Mat::ones(x,y,CV_8UC3); //note 8UC3 instead of 8UC1
   cv::Vec3b px3 = img_C3.at&lt;cv::Vec3b&gt;(0,0);
   printf("px of 3-channel img: %d %d %d \n", (int)px3[0], (int)px3[1], (int)px3[2]); //prints 1 0 0
  }
  </code></pre>
  
  <p>So, I would have expected to see this printout: <code>px of 3-channel img: 1 1 1</code>, but instead I see this: <code>px of 3-channel img: 1 0 0</code>. </p>
  
  <p>P.S. I did a lot of searching before posting this. I wasn't able to resolve this by searching SO for "[opencv] Mat::ones" or "[opencv] +mat +ones".</p>