title: Conversion of an image grabbed with MIL-lite to use it with OpenCV
body: <p>I have been searching a solution on the internet for almost 2 days but what I found doesn't seem to work on my computer.</p>
  
  <p>What I'm using : </p>
  
  <ul>
  <li>Matrox Vio DUO</li>
  <li>OpenCV 2.4.5</li>
  <li>MIL-lite</li>
  <li>Ubuntu 10.04</li>
  </ul>
  
  <p>I have already tried the cvcap_mil.cpp file that you can find <a href="https://code.ros.org/trac/opencv/browser/trunk/opencv/src/highgui/cvcap_mil.cpp?rev=1714" rel="nofollow">here</a>.</p>
  
  <p>This code isn't working for my project too :</p>
  
  <pre><code>   IplImage* rgb_frame;
     rgb_frame = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3 );
     MilImage = MbufAllocColor(MilSystem, 3, w, h,8+M_UNSIGNED,M_IMAGE + M_GRAB,M_NULL);
     MbufGetColor(MilImage, M_BGR24+M_PACKED, M_ALL_BAND, (void*)(rgb_frame-&gt;imageData));
     rgb_frame-&gt;origin = IPL_ORIGIN_BL;
     cvFlip(rgb_frame,rgb_frame,0);
  </code></pre>
  
  <p>Do you have any idea how to do it ?</p>
  
  <p>PS : My Matrox Vio card is working fine. </p>
  
  <p>EDIT : I found a way to grab black and white images. Here is the solution for those interested :</p>
  
  <pre><code>MIL_ID MilApplication, /* Application identifier */
  MilSystem, /* System identifier */
  MilDigitizer, /* Digitizer identifier */
  MilImageRGB, /* RGB Buffer */
  MilImage1Child, /* R child */
  MilImage2Child, /* G child */
  MilImage3Child; /* B child */
  
  //init
  MappAlloc(M_DEFAULT,&amp;MilApplication);
  MsysAlloc(M_SYSTEM_VIO,M_DEFAULT,M_DEFAULT,&amp;MilSystem);
  
  MdigAlloc(MilSystem,M_DEFAULT,MIL_TEXT("M_DEFAULT"),M_DEFAULT,&amp;MilDigitizer);
  
  /*get width &amp; height of cam*/
  long width = MdigInquire(MilDigitizer,M_SIZE_X,M_NULL);
  long height = MdigInquire(MilDigitizer,M_SIZE_Y,M_NULL);
  MbufAllocColor(MilSystem,3,width,height,8+M_UNSIGNED,M_IMAGE+M_GRAB+M_PROC+M_DISP,&amp;MilImageRGB); /*Erster Buffer*/
  
  /*first Child (r channel)*/
  
  MbufChildColor2d(MilImageRGB,M_RED, 0, 0, width , height ,&amp;MilImage1Child);
  MbufChildColor2d(MilImageRGB,M_GREEN, 0, 0, width , height ,&amp;MilImage2Child); /*second Child (g channel)*/
  MbufChildColor2d(MilImageRGB,M_BLUE, 0, 0, width , height ,&amp;MilImage3Child); /*third Child (b channel)*/
  IplImage *pIplImgProcessed = cvCreateImage ( cvSize ( width,height ), 8,1 );
  
  /* get one image */
  MdigGrab(MilDigitizer, MilImageRGB);
  
  
  /*copy first child to buffer*/
  MbufGet ( MilImage1Child, pIplImgProcessed-&gt;imageData );
  
  
  
  // Visualise in a Qt label
  Mat src(pIplImgProcessed);
  QImage qImage = Mat2QImage(src);
  QPixmap pixmap = QPixmap::fromImage(qImage);
  ui-&gt;label_2-&gt;clear();
  ui-&gt;label_2-&gt;setPixmap(pixmap.scaled(ui-&gt;label_2-&gt;size()));
  
  
  //release
  MdigFree(MilDigitizer);
  MbufFree(MilImage1Child);
  MbufFree(MilImage2Child);
  MbufFree(MilImage3Child);
  MbufFree(MilImageRGB);
  MsysFree(MilSystem);
  MappFree(MilApplication);
  </code></pre>
  
  <p>Thank you for your help.
  Thibaut.</p>