Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

ImaqBuffer? where is the structure used in imgSnap() defined?

how does one get access to the pixel data following a call to imgSnap()?, I have looked at the ImaqBuffer (from the examples) the info must be there but I can't find any information on what the details of the image data structure are defined as. I am working in C++, any ideas on where I can find the definition of the image data? Thanks in advance

-Russ
0 Kudos
Message 1 of 10
(4,973 Views)
Russ,
This should be a pointer to the array of data...attached is an example that should be useful.
Chris D
0 Kudos
Message 2 of 10
(4,973 Views)
Example is (somewhat) useful but does not directly answer the question. It appears from the example that the buffer is pixels in bytes without alignment padding but are these bytes RGB, BGR? There is never alignment bytes? I take it these is not a structure at all but this is simply a pointer to contiguous pixel data?
0 Kudos
Message 3 of 10
(4,973 Views)
Hi Ron, yes I agree it is just a pointer, I am only grabbing 8 bit mono frames so I cannot comment on the RGB or BGR question, what I did find is that the actual pixel data starts at an offset of 0x386 to the ImaqBuffer pointer. Everything preceding this location appears to be nulls (very intuitive). This is all the information I need for my purposes but If I was working in color it would be a different story.
0 Kudos
Message 4 of 10
(4,973 Views)

Hi I have a similar problem. Im finding it impossible to get the array of image pixel data

 

Does anyone knwo how I can convert ImaqBuffer into a pixel array of short[]?

 

The source code examples have this kind of code;

 

ImaqBuffer = (Int8 *)malloc(320 * 256 * 2);

Int32 err = imgGrab (Sid, (void **)&ImaqBuffer, TRUE);

 

 

ImaqBuffer should contain the pixel data but it just seems to contain garbage.

 

Then the example code uses the function imgPlot2  to display the image.

 

imgPlot2 (ImaqSmplHwnd, ImaqBuffer, 0, 0, AcqWinWidth, AcqWinHeight,

CanvasLeft, CanvasTop, plotFlag);

 

 

But I dont want to use imgPlot2 i just want to read the pixel data and manipulate it. Ive spent hours trying to do this but with no success.

 

Note. I wanted to use the DotNet librarires but they throw an error because apparently I have an older version of the software somewhere in the bowels of my PC.

 

TIA

0 Kudos
Message 5 of 10
(3,914 Views)

 

OK I tried looking at the example further up this thread but this hasnt helped. Its something similar to what I previously tried. Ive also tried searching the other boards but to no avail.

 

Our camera has a 320*256 pixel 14 bit image. I simply need to be able to access the data for each pixel. I honestly cannot believe how difficult this appears to be to do.Unfortunately the examples don't help at all. The ironic thing is there is a DOTNET sample that has an "ExtractedPixels" function that does what I want but it isn't supported for 64 bit Windows.

 

Any example C/C++ code anywhere that shows this?

 

HELP!!

0 Kudos
Message 6 of 10
(3,887 Views)

Ive been looking at the llgrab.c (low level grab) example in the sample programs.  This line copies the image from the camera into CopyBuffer which is a pointer to a pointer

 

errChk(imgSessionCopyBufferByNumber(Sid, currBufNum, CopyBuffer, IMG_OVERWRITE_GET_NEWEST, &actualCopiedBuffer, NULL));

 

Then the image is displayed using imgPlot2

 

errChk(imgPlot2 (ImaqSmplHwnd, CopyBuffer, 0, 0, AcqWinWidth, AcqWinHeight,

CanvasLeft, CanvasTop, plotFlag));

 

Does anyone know if &actualCopiedBuffer contains the actual pixel data of the image?

Ive tried the following to try and get access to the image data, however its throing an exception.

 

memcpy_s(myImage, sizeOfImage, actualCopiedBuffer, sizeOfImage);

 

where;

 

int sizeOfImage = 32- * 256 * 2;

WORD* myImage = (WORD*)malloc(sizeOfImage);

 

 

Is there anything obvious Im doing wrong here?

 

TIA

0 Kudos
Message 7 of 10
(3,871 Views)

Sorry that should be;

 

Ive been looking at the llgrab.c (low level grab) example in the sample programs.  This line copies the image from the camera into CopyBuffer which is a pointer to a pointer

 

errChk(imgSessionCopyBufferByNumber(Sid, currBufNum, CopyBuffer, IMG_OVERWRITE_GET_NEWEST, &actualCopiedBuffer, NULL));

 

Then the image is displayed using imgPlot2

 

errChk(imgPlot2 (ImaqSmplHwnd, CopyBuffer, 0, 0, AcqWinWidth, AcqWinHeight,

CanvasLeft, CanvasTop, plotFlag));

 

Does anyone know if &actualCopiedBuffer contains the actual pixel data of the image?

Ive tried the following to try and get access to the image data;

 

memcpy_s(myImage, sizeOfImage, actualCopiedBuffer, sizeOfImage);

 

where;

 

int sizeOfImage = 320 * 256 * 2;

WORD* myImage = (WORD*)malloc(sizeOfImage);

 

 

However the program is throwing an exception  at my line "memcpy_s(myImage, sizeOfImage, actualCopiedBuffer, sizeOfImage);"

Is there anything obvious Im doing wrong here?

 

TIA

0 Kudos
Message 8 of 10
(3,870 Views)

Im not sure whats happening in the above code. However Ive managed to find a solution. Ive set up a buffer ring and used the following to get an image

 

 imgSessionExamineBuffer2 (gSessionID, gBufNum, &vCurrBufNum,(void**)&vBufAddr);

 

Now if I do this;

 

memcpy_s(myImage,sizeOfImage,vBufAddr,sizeOfimage);

 

 

I have all my pixel data in myImage!

0 Kudos
Message 9 of 10
(3,861 Views)

None of your posts include the rest of your code, so it is hard to really understand what the problems you are encountering are from just the few lines posted. However, my best guess is that your code is interpreting your 14-bit data (strored by the framegrabber as 16-bit data) as 8-bit data, so that is why you are seeing garbage.

 

In your last snippet of code you posted, you are simply copying the data from the buffer in the IMAQ ring to a buffer you allocate. Since both buffers are the same size in bytes and you are copying one to the other, the only logical conclusion is that the difference in pointer type is why you see "good" data in one and "bad" data in the other. You could logically replace the memcpy with WORD* myImage = (WORD*)vBufAddr; and achieve the same result without copying the data. If you simply declared the pointer to be to 16-bit data in the first place you wouldn't need the cast even.

 

Eric

0 Kudos
Message 10 of 10
(3,849 Views)