From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

[NI Vision DLL] [C++] [IMAQ DLL] [IMAQ C Support] [Pass image from C to LV] How to Copy raw U16 data to LabVIEW Vision Image Buffer using memcpy()?

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: 

Achuthaperumal_0-1632288830556.png

 

 

The Parameter Configuration 

Achuthaperumal_1-1632288830715.png

 

 

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:

Achuthaperumal_2-1632288830600.png

 

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! 

Achuthaperumal_3-1632288830586.png

 

 

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:

Achuthaperumal_4-1632288830605.png

 

 

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!

0 Kudos
Message 1 of 1
(708 Views)