Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use IMAQdxGetAttribute to get a string value of an attribute?

I have a simple acquisition program written in C/C++ that used NI-IMAQ. I am now in the process of adding NI-IMAQdx support to my program.

With IMAQ I used imgGetAttribute to get the bits per pixel, the bytes per pixel, the height, and the width of the image. In IMAQdx, I'm trying to use IMAQdxGetAttribute. Problem is when I try to get the bits/bytes per pixel for a color camera it returns 0, and when I try to request the mode I get a seemingly random number. The number is consistent, but I can't relate it to what mode it is actually in.

Can I use IMAQdxGetAttribute to get a string description of the video mode? If so how do I do that? I tried creating a "char str[256];" but I get an access violation when I try that.

Thanks,
-Josh
0 Kudos
Message 1 of 7
(4,435 Views)
Hi Josh,
 
To get attributes as strings you can do as follows:
 
char attributeValue[IMAQDX_MAX_API_STRING_LENGTH]
IMAQdxGetAttribute(session, "BitsPerPixel", IMAQdxValueTypeString, attributeValue);
 
The third parameter reflects not the attribute's type, but rather the API data type you are passing to GetAttribute. IMAQdx will do appropriate conversion (if possible) between the attribute's native type and the requested data type.
 
For your specific question regarding bits-per-pixel, it is a little inconvenient but we do not have an explicit attribute that will give you an integer number of bits in the resulting imagel. The "BitsPerPixel" is actually a hint to the decoder and display as to what the bit depth of the resulting image will be, and as you may be able to see in MAX it defaults to "use Hardware Value" (which for most firewire and all GigE cameras should be detected automatically). However, you can deduce the pixel depth from the "PixelFormat" attribute, which will return something like "Mono8" or "BayerBG10". On FireWire there is a VideoMode attribute that will give you a string description of the overall mode as well.
 
Hope this helps,
Eric
0 Kudos
Message 2 of 7
(4,431 Views)

Thanks Eric, that answered my question! I've got it working now. Next I just have to figure out how to demosaic the Bayer format into RGB. Know of any C/C++ routines to do so? Thanks!!!!

-Josh

0 Kudos
Message 3 of 7
(4,377 Views)
You want to do it manually? IMAQdx will do it automatically when grabbing the image buffer. If the pixel format is identifiable as a Bayer format the conversion should happen automatically. You can override the pattern and enable/disable it with an attribute as well. This allows you to enable bayer decoding on a camera that doesn't advertise a bayer sensor, for instance.
 
In any case, you're probably get better performance using IMAQdx's Bayer decoding than one written yourself because IMAQdx will take advantage of MMX/SSE and other CPU-specific features to improve the speed of the decoding. These make a huge difference compared to a simple C implementation of the basic algorithm.
 
-Eric
0 Kudos
Message 4 of 7
(4,369 Views)
How is this done? On pixel format for the color GigE camera I have it only gives me Mono 16, Bayer BG16, another Bayer option, and some YUV options, I don't see RGB in the list. Thanks for any tips,
-Josh
0 Kudos
Message 5 of 7
(4,367 Views)
Josh,
 
If you select BayerBG16 as the format and have the bayer decoding set to Auto, the IMAQdx driver will convert it to automatically to RBG when you grab the image. The same applies to YUV modes. Unless you extract the raw images as a data buffer, the images acquired by IMAQdx will always come to your application as RBG or Mono formats as appropriate.
 
Eric
0 Kudos
Message 6 of 7
(4,364 Views)
Eric,
The function I'm using is IMAQdxGetImageData, which I understand always gets the raw image. The other image grabbing function, IMAQdxGetImage, I think the one you're referring to, returns an IMAQ Image. I'm not sure how to work with these. The program I'm working on is a high speed video recorder, in which I continously grab the images and write them to disk as fast as I can. Right now I'm able to simultaneously capture at least four cameras that are each 640x512x16bpp at 30Hz without dropping any frames. I'm trying to keep things fast and reliable, and I'm still not sure how to get RGB data to write directly to disk with an IMAQ Image type.
 
Thanks for your help Eric!
-Josh
0 Kudos
Message 7 of 7
(4,352 Views)