title: C++: Grayscale bitmap header and live painting + opencv image processing
body: <p>I am trying to display live images coming from a monochrome camera (Adimec N5A/CXP, with GenIcam standard).</p>
  
  <p>From an example coming from the supplier (but in RGB 24), I am more or less able to display the image but the color rendering is very strange (colors and shadows instead of grayscale). I guess I did something wrong in the bitmap header declaration: </p>
  
  <pre><code>    bitmapInfo = (LPBITMAPINFO)malloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD));
      bitmapInfo-&gt;bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
      bitmapInfo-&gt;bmiHeader.biPlanes = 1;
      bitmapInfo-&gt;bmiHeader.biBitCount = 8; // 24
      bitmapInfo-&gt;bmiHeader.biCompression = BI_RGB;
      bitmapInfo-&gt;bmiHeader.biSizeImage = 0;
      bitmapInfo-&gt;bmiHeader.biXPelsPerMeter = 0;
      bitmapInfo-&gt;bmiHeader.biYPelsPerMeter = 0;
      bitmapInfo-&gt;bmiHeader.biClrUsed = 256;
      bitmapInfo-&gt;bmiHeader.biClrImportant = 0;
      bitmapInfo-&gt;bmiHeader.biWidth = (LONG)width;
      bitmapInfo-&gt;bmiHeader.biHeight = -(LONG)height;
      /*
      RGBQUAD* bmiColors = (RGBQUAD*)(bitmapInfo-&gt;bmiColors);
      for (size_t index = 0; index &lt; 256; ++index)
      {
          bmiColors[index].rgbBlue = (BYTE)index;
          bmiColors[index].rgbGreen = (BYTE)index;
          bmiColors[index].rgbRed = (BYTE)index;
          bmiColors[index].rgbReserved = 0;
      }
      */
  </code></pre>
  
  <p>I found in <a href="https://stackoverflow.com/questions/21558911/bmicolors-field-of-bitmapinfo-structure">bmiColors field of BITMAPINFO structure</a> that the 'biClrUsed' should be set to 256. Then I do not know if I need to write a block to describe 'bmiColors'. I would like to use only one byte per pixel instead of the r,g and b components. </p>
  
  <p>Then further in the program (in the function "OnPaint"), it uses the function "SetDIBitsToDevice" to display in a window previously created. The image pointer is first retrieved: </p>
  
  <pre><code>unsigned char *imagePtr = liveState.currentBuffer-&gt;getInfo&lt;unsigned char *&gt;(liveState.grabber, gc::BUFFER_INFO_BASE);
  </code></pre>
  
  <p>Then the image is displayed:</p>
  
  <pre><code>::SetDIBitsToDevice(dc, 0, 0, (DWORD)liveState.width, (DWORD)liveState.height, 0, 0, 0, (UINT)liveState.height, imagePtr, liveState.bitmapInfo, DIB_RGB_COLORS);
  </code></pre>
  
  <p>I don't know what to put instead of DIB_RGB_COLORS as the last parameter. I only found another value for this parameter that is DIB_PAL_COLORS. I guess there should be an option for grayscale? </p>
  
  <p>This is the first step of my program... if you have any suggestion on how to push the image pointer into an opencv container I would also be very happy :-). </p>
  
  <p>Many thanks in advance !</p>