title: EMGU: BayerGB 8bit to Image<Bgr, byte>
body: <p>I have a byte array generate from a camera.
  I want to convert this c# array (<em>byte[] myBuffer</em>) to a Emgu BgrImage.</p>
  
  <p>The RAW image from the camera has 2590 x 1940 pixel.
  The format is the BayerGB 8bit, so there are 2590(cols) x 1940(rows) x 2(byte) = 10059560 bytes.</p>
  
  <p>I grab the data form the camera and I have a byte array with the data</p>
  
  <pre><code>byte[] myBuffer = myGrabberFuncion();
  //myBuffer.lenght == 10059560 
  </code></pre>
  
  <p>now I want to convert it to a BGR Image. I think I should use the <strong><em>Emgu.CV.CvInvoke.CvtColor(SRC, DEST, COLOR_CONV, CHANN )</em></strong> function.</p>
  
  <p>But i can't feed the function with a byte[] as the SRC argument, as it needs a "IInputArray".</p>
  
  <p>So I can feed in a <strong>Mat</strong>, or a <strong>Matrix</strong>, or an <strong>Image&lt;# , #></strong></p>
  
  <p>But how should I put "buffer" data in to one of this structures?</p>
  
  <p>If I use <code>Matrix&lt; byte &gt; Bayer = new new ecv.Matrix&lt;byte&gt;(rows, cols, channels)</code> I can't set 1 channel, because it would contain half the bytes of  <strong>myBuffer</strong> </p>
  
  <p>I can't set it to 2 channels, because an "assert" of the Opencv tells me that the color conversion <code>CvEnum.ColorConversion.BayerGb2Bgr</code> wants a 1-channel input image (it tells: <code>OpenCV: scn == 1 &amp;&amp; (dcn == 3 || dcn == 4)</code>)</p>
  
  <p>I tried, as a work-around, to make a image  with double width and convert this image, this don't give an error, but the output image is black (all zeroes)</p>
  
  <pre><code>byte[] buffer = myGrabberFunction();
  
  Image&lt;Structure.Bgr, byte&gt; lastFrameBgr = new Image&lt;Structure.Bgr, byte&gt;(2590, 1942);
  
  //test with Matrix of bytes:
  ecv.Matrix&lt;byte&gt; bayerMatrix = new ecv.Matrix&lt;byte&gt;(lastFrameBgr.Height, lastFrameBgr.Rows, 2);
  bayerMatrix.Bytes = buffer;
  ecv.CvInvoke.CvtColor(bayerMatrix, lastFrameBgr, ecv.CvEnum.ColorConversion.BayerGb2Bgr, 3);
  //result in a black Image
  
  
  //test with an 1 channel Byte depth image   
  Image&lt;Structure.Gray, byte&gt; bayerGrayImage = new Image&lt;Structure.Gray, byte&gt;(lastFrameBgr.Width * 2, lastFrameBgr.Height);
  bayerGrayImage.Bytes = buffer;
  ecv.CvInvoke.CvtColor(bayerGrayImage, lastFrameBgr, ecv.CvEnum.ColorConversion.BayerGb2Bgr, 3);
  //result in a black Image
  </code></pre>
  
  <p>My Question:
  How can i transform my array of bytes in something i can use as source in Emgu.CV.CvInvoke.CvtColor(... ) funcion?</p>
  
  <p>Or How should I do to convert am array of bytes into a Emgu Bgr Image?</p>