09-22-2021 12:41 AM
I have a frame grabber that acquires 16bit grayscale image data as a 1d array of unsigned short
. Now I need to convert this raw U16
data to a LabVIEW Vision Image for further processing.
Before proceeding with the actual acquisition, I thought of experimenting with the NI Vision Library Support for C++. I have slightly modified example code from NI to copy a Grayscale U8
image using memcpy()
. When I run, for Grayscale U8
, It works.
For the initial test, I created a Grayscale U8 type Image Buffer in LabVIEW and passed the pointer to the Image Handle:
The Parameter Configuration
C++ Function:
#include "nivision.h"
//Image Data as LabVIEW Cluster
typedef struct {
char* name;
Image* address;
}IMAQ_Image;
int __stdcall copyImageToLV(IMAQ_Image *LVImage)
{
Image* myImage, *lvImage;
PixelValue pixel;
ImageInfo myImageInfo, lvImageInfo;
int y, LVHeight, LVWidth;
lvImage = LVImage->address;
pixel.grayscale = 128;
//Create a New Image buffer and fill it with grey.
myImage = imaqCreateImage(IMAQ_IMAGE_U8, 3);
imaqGetImageSize(lvImage, &LVWidth, &LVHeight);
imaqSetImageSize(myImage, LVWidth, LVHeight);
imaqFillImage(myImage,pixel, NULL);
imaqGetImageInfo(myImage, &myImageInfo);
imaqGetImageInfo(lvImage, &lvImageInfo);
//LVImage->address = myImage;
//Copy filled Image to Buffer created from LabVIEW
for (y = 0; y < LVHeight; ++y)
{
memcpy((char *)lvImageInfo.imageStart + y * lvImageInfo.pixelsPerLine,
(char *)myImageInfo.imageStart + y * myImageInfo.pixelsPerLine, LVWidth);
}
imaqDispose(myImage);
return 0;
}
The Output:
Then I tried to implement the same for Grayscale U16
by changing the following lines:
pixel.grayscale = 32000;
myImage = imaqCreateImage(IMAQ_IMAGE_U16, 3);
.
.
.
for(y=0;y<LVHeight;++y){memcpy((unsigned short*)lvImageInfo.imageStart + y * lvImageInfo.pixelsPerLine,
(unsigned short*)myImageInfo.imageStart + y * myImageInfo.pixelsPerLine, LVWidth);}
I get the following Image with a pixel value of 32000 from 0 to 49th columns and pixel value of 0 from 50 to 99 as output!
Then I tried the following:
pixel.grayscale = 32000;
myImage = imaqCreateImage(IMAQ_IMAGE_U16, 3);
.
.
.
for(y=0;y<LVHeight*2;++y){ memcpy((char*)lvImageInfo.imageStart + y * lvImageInfo.pixelsPerLine,
(char*)myImageInfo.imageStart + y * myImageInfo.pixelsPerLine, LVWidth*2);}
I get the following Blank Image with a pixel value of 32000 as output:
I even tried instead of copying the data, I just swapped the address and removing the Dispose part:
LVImage->address = myImage;
//for(y=0;y<LVHeight*2;++y)//{//memcpy((char*)lvImageInfo.imageStart + y * lvImageInfo.pixelsPerLine,
// (char*)myImageInfo.imageStart + y * myImageInfo.pixelsPerLine, LVWidth*2);
//ImaqDispose(myImage);
Still, I'm getting the same blank Image!
Can anyone help me in copying the data? Any help would be really appreciated... Thanks!