LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

From NI's 'Image' type to OpenCV's 'IplImage' type...

Hello,

I am using LabWindows/CVI's 'grab' project. I can grab images from the camera connected to the NI card. How it does this? It does this in the GrabNewImage function:

 

   myImage = imaqGrab (sid, myImage, FALSE);
   imaqDisplayImage (myImage, 0, 1);

 

And myImage is declared as an 'Image*'  type:

   static Image* myImage = NULL; 

 

I want to call OpenCV functions. But I cannot. I should have an image type of Iplimage*:

 

How can I convert from 'Image' type to 'Iplimage' type?

 

What about?

IplImage* frame = 0;

frame = cvCreateImage( _size, IPL_DEPTH_8U, 4 );

frame->imageData = myImage*;

 

Will it work?

 

Thank you so much!!

 

Message Edited by kbv2842 on 08-18-2008 02:51 PM
0 Kudos
Message 1 of 5
(6,321 Views)

Hi kbv2842,

 

Can you please explain to me why you need to convert to the Iplimage data type? I understand that you are able to use the grab function to pull images from your NI framegrabber, but are you not able to use the OpenCV function? Are you getting an error?

--Michelle

National Instruments
0 Kudos
Message 2 of 5
(6,280 Views)

no this assignment will not work, you will need a more advanced conversion. 

 

you can find a pointer to the first pixel of your NI image by calling imaqGetImageInfo(): it is stored in the imageStart member of the structure returned by the function. then you will have to be careful about borders, padding and the likes: a line of pixel is pixelsPerLine wide. you may have a way to specify padding when creating the OpenCV image: after looking quickly to OpenCV documentation, InitImageHeader() is the only function that allows you to specify padding. then you have the problem of datatypes: if you are using 8bit grayscale images then you are fine, but if you are using color images you have to pay attention to the color encoding (rgb, yuv, or other, generally you have an rgb image) and channel ordering (red, green and blue components of an rgb imagemay appear in a different order). now that you are aware of all the peculiarities of image conversion, you can write your conversion (i am confident it will be straighforward). now you have to be careful that OpenCV functions do not reallocate or move the memory block containing the pixel data or you will not be able to use you NI image anymore. 

 

i am confident the conversion function is straighforward: use the cvInitImageHeader function with the right arguments, then set the imageData member of the OpenCV image.

0 Kudos
Message 3 of 5
(6,263 Views)

I need to do the conversion so that I can use the imaqScale() function. The imgGrab() function returns a pointer type while the imaqScale() function requires the pre-defined image type (Image). I have got it to work, just before the next post. and I will post soon how we did it.

Thanks again.

0 Kudos
Message 4 of 5
(6,259 Views)

IplImage* grabImage()
{

   SESSION_ID session;
   IMAQdxError status;
   uInt32 bufferNumber;
   Image* image;

 

   /** Initialize camera here **/

 

  status = IMAQdxOpenCamera ("cam0", IMAQdxCameraControlModeController, &session);
   if( status )
      std::cerr << "Could not open camera\n";
   status = IMAQdxConfigureGrab (session);
   if( status )
      std::cerr << "Could not configure camera\n";
   status = IMAQdxGrab (session, image, TRUE, &bufferNumber);
   if( status )
      std::cerr << "Could not grab\n";

   ImageInfo info;

   imaqGetImageInfo(image, &info);

   // 4 Channels seems to work for us. We have a color camera, so you would expect 3

   // channels, but I think the extra one just basically fills up the last 8 bits of a 32-bit color

   // field.

   IplImage* ret = cvCreateImageHeader( cvSize(info.xRes, info.yRes), IPL_DEPTH_8U, 4 );
   std::cerr << info.pixelsPerLine << " " << info.xRes << " " << info.yRes << "\n";
   std::cerr << info.border << "\n";
   ret->imageData = (char*)info.imageStart;

   return ret;
}

Message 5 of 5
(5,259 Views)