Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

get image data in vc++

hi  all,
 
i'd like to use vc++ to process image data (read/modify pixel values, display the image, etc.) through imaq library.
sample code:

// get the frame

imgGrab (Sid, &ImaqBuffer, TRUE);

// display it using imgPlot

imgPlot ((GUIHNDL)ImaqSmplHwnd, ImaqBuffer, 0, 0, AcqWinWidth, AcqWinHeight,

CanvasLeft, CanvasTop, plotFlag);

imaqBuffer ist the buffer for storing image data, which was declared as follows:

static

 char *ImaqBuffer=NULL; // acquisiton buffer

How can i get the image data from "ImaqBuffer"? (how to get the buffer size?)

thx a lot!

scott

0 Kudos
Message 1 of 8
(4,105 Views)


Hi Scott, wit installing NI-IMAQ you will get examples.  You can find them in C:\Programme\National Instruments\NI-IMAQ\Sample\MSVC\Grab I think they will answer your question.

Thanks, Rebecca

NI, Germany Applications Engineer

Rebecca Fox
Applications Engineer
National Instruments
0 Kudos
Message 2 of 8
(4,087 Views)

hi rebecca,

thanks for the reply. i've already installed ni-imaq, and the code i posted was actually from their grab examples.

after finding out the size of the buffer (width x height x bytes per pixel), i can get the raw data from the buffer and write them into a file through:

FILE* f = fopen("ImaqBuffer.txt", "a+");

for (i=0; i<bufSize; i++)

    fprintf(f, "%u ", ImaqBuffer[i]);      # %u for unsigned char

but i have another problem. the data i got are pixel values in sequence of (Blue Green Red Alpha). when the value is greater 127 (theoretically max. 255 due to 8bits for each color), it becomes value-256+2^32, e.g. instead of (199 115 79 0) for a certain pixel, i got (4294967239 115 79 0 ). by using "%d ", i got (-57 115 79 0). and by "%2x ", i got (ffffffc7 73 4f 0). how could fprintf behave like this or it's some magic by imaq grab function?
 
scott
0 Kudos
Message 3 of 8
(4,077 Views)

hi,

i just found out, if i change the declaration of ImaqBuffer into:

static

unsigned char *ImaqBuffer = NULL;

and instead of letting IMAQ manage the buffer size, i manually set the size by:

ImaqBuffer = (

unsigned char *) malloc(bufSize * sizeof (unsigned char));

then i can get the reasonable pixel values with fprintf.

anyone from NI could explain this?

scott

0 Kudos
Message 4 of 8
(4,067 Views)

hi all,

why do the pixel values in the image buffer, which is set by imgGrab(), use the BGRA model instead of RGBA ('A' stands for alpha) model ?

e.g. i get (23, 35, 55, 0) for a certain pixel, whose color is actually (55, 35, 23, 0) in RGBA. it's not that annoying if only a few pixels should be processed, but one can imagine for a large amount of pixels... to convert BGR to RGB is not hard, but quite inefficient for some online image processing.

anybody from NI can explain this "feature"? thanks a lot!
 
scott
0 Kudos
Message 5 of 8
(4,047 Views)

Hi Scott,

I think now I´m understanding your question...you have got an image and want to extract the several color palets and then convert them into their raw data.  T do this you should take first IMAQExtractColorPlans and then IMAQImageToArray. this functions are from CVI but they should be in Visual Studio C++ too. I hope this is answering your questions.

Rebecca Fox

National Isntruments, Germany

Rebecca Fox
Applications Engineer
National Instruments
0 Kudos
Message 6 of 8
(4,035 Views)

hi Rebecca,

thanks for your reply! actually i get raw data stored in a buffer through imgGrab() (defined in niimaq.h), and what i don't understand is that the raw data in the buffer, which are already color values of four channels, use BGRA format instead of the "more popular" RGBA.

btw, i don't find IMAQExtractColorPlans and IMAQImageToArray. I am developing applications based on the NI-IMAQ User Manual, and the only library i am using is imaq.lib (and the header file niimaq.h, which gives me all the functions i can use).

anyway, dealing with BGRA values is not that complicated as i thought.
 
scott
0 Kudos
Message 7 of 8
(4,030 Views)
Hi Scott
ok, then we have an answer. The functions are from Vision not from NI-IMAQ. You should by Vision to use it.
Rebecca
National Instruments, Germany
Rebecca Fox
Applications Engineer
National Instruments
0 Kudos
Message 8 of 8
(4,025 Views)