Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Imaq: How to extraxt the image array from the imaq buffer in C?

I am relatively new to IMAQ, and am currently working off of a variation of the sequence code example.  I'm currently capturing a sequence of images, but then I want to manipulate them with my own processing algorithms.  I have the array of ImaqBuffers that point to each image (which from what I have read is a 2D array of pixel values).  My question is, how do I extract each image array from the buffer for my own manipulation?  I have used imgSessionSaveBufferEx() to write each buffer to a bitmap file, but what I really want to do is just extract the array data so I can process it.  Does anyone know how to accomplish this?  Any help would be greatly appreciated!!

Thank You,
Justin Mahood
0 Kudos
Message 1 of 10
(5,574 Views)
Any input at all on this problem would be greatly appreciated.  I am getting fairly desperate. 

Thanks!
Justin
0 Kudos
Message 2 of 10
(5,567 Views)
Hi Justin
    You should look at the image to array function as a very quick and easy solution to your problem

imaqImageToArray

Usage

void* imaqImageToArray(const Image* image, Rect rect, int* columns, int* rows);

Purpose

Creates a two-dimensional array from an image.


Hope that helps

Mike
0 Kudos
Message 3 of 10
(5,565 Views)
Thank you Mike, I really appreciate the help.  Unfortunately I am not capturing into Imaq Vision image* format.  I'm using the NI-Imaq libraries and only getting an array called *ImaqBuffers[i].  Is there any analog to that function for this capture format?

Thanks,
Justin
0 Kudos
Message 4 of 10
(5,558 Views)
OK Justin
    Using the function

imgGetBufferElement

Usage

rval imgGetBufferElement(BUFLIST_ID bid, uInt32 element, uInt32 itemType, void* itemValue);

Purpose

Gets the value for a specified itemType for a buffer in a buffer list.

Parameters

Name Type Direction
bid BUFLIST_ID input
element uInt32 input
itemType uInt32 input
itemValue void* output
rval Int32 output

Will allow you to get the start address and the length of the buffer so you can see the size of the array you ned to copy it into. Different values into itemtype will get the start address and the bufsize.

Hope that helps

Mike
0 Kudos
Message 5 of 10
(5,551 Views)

How would the imgGetBufferElement(...) function be implemented?

 

For example, I have a image buffer populated by the imgSnap(...) function.  The buffer is declared as:

 

Int8* imaqbuffer=NULL;

 

how does this imaqbuffer go into the imgGetBufferElement(...) function to create a 2D integer array ( i[256][320] )?

 

I am using a 12-bit ALPHA NIR camera from FLIR technologies.  Currently, I can save the images using the imgSaveBufferEx(...) function, but I also have to use the values of each individual pixel to do a few image processing manipulations.

0 Kudos
Message 6 of 10
(4,829 Views)

Hi Vs3,

 

In the example code you are using, ImaqBuffer is the 2D array of your pixels. It is simply a block of memory that matches your width*height*bytes per pixel.

 

Eric

0 Kudos
Message 7 of 10
(4,816 Views)

So how do I put that into a form i can use?

 

I've tried reading values in the visual studio debugger by accessing imaqbuffer[100][100] but I get an out of range error.

 

I can get a value by accessing imaqbuffer[100], but this value comes out to be meaningless to me...  I am looking for a 2D array of 12-bit integers (0-4095)

 

Is the buffer simply a long string of bytes that I have to split up?  is each 12-bit value from my camera stored as a word, or do every 3 bytes contain 2 pixels?

 

I have to do some image ratios, and I would like to have a simple var[][] identifier to use in my for loops.

0 Kudos
Message 8 of 10
(4,805 Views)

vs3,

 

Your debugger won't let you access the data using the 2D array syntax because it is defined in the code as a pointer to a byte array but you want to access it as a 2D array of 16-bit integers (your 12-bit image data cannot be efficiently accessed in 12-bit form, so the IMAQ board always transfers it into 16-bit integers). You would simply cast the pointer to the format you need before dereferencing it. Note that in C, using 2D array syntax is tricky unless you hardcode the dimensions of such an array in your code. You are much likely better off treating it as a 1D array and accessing it as follows: imageData[y*width+x].

 

Eric

0 Kudos
Message 9 of 10
(4,802 Views)

ah, okay...

 

so if I cast the buffer as a 16-bit integer, I will see the numbers that I am looking for in a 1D array?

 

what if I changed the declaration from Int8* to Int16*?  I tried this earlier except I get a compilation error that Int16 is ambiguous so I haven't looked into it any farther yet.

 

all of my images are 318x256 pixels, which is why I am leaning toward a int[][] over a vector< vector<int> >.

0 Kudos
Message 10 of 10
(4,794 Views)