01-15-2020 08:11 PM
I can't get this code to work:
int TestImage(Image *image)
{
PixelValue pixelValue;
MessageBoxA(0, "Start", "Info", MB_OK);
image = imaqCreateImage(IMAQ_IMAGE_U8, 3);
if (image == NULL) {
MessageBoxA(0, "Create image failed.", "Error", MB_OK);
}
if (imaqSetImageSize(image, 100, 100) == 0) {
MessageBoxA(0, "Set image size fail.", "Error", MB_OK);
}
pixelValue.grayscale = 128;
imaqFillImage(image, pixelValue, NULL);
return imaqGetLastError();
}
No error.
Image is blank. Size is 0.
TIA
Solved! Go to Solution.
01-16-2020 10:16 AM - edited 01-16-2020 10:23 AM
01-16-2020 10:33 AM - edited 01-16-2020 10:41 AM
Thanks for reply Andrey.
I got the idea from your post at:
Where Greg said you don't need the test image.
If you take a look the diagram of IMAQ Create, it uses the image as input, not image cluster.
I don't know the image size/pixel format before I call the dll. So I have to create image and set image size inside the dll.
I got multiple cameras, from vendors SDK, I can't specify which camera. Each time I call the dll, I lock onto a the "first" camera driver finds.
By the way, we have already tried IMAQdx. Can't get it to work. Got a lot of black stripes on the image. the position and width are random. It might be a band with issue? On the other hand, vendor's viewer has no problem to get right image.
01-16-2020 12:26 PM
You can pass image directly, but then you should call LV_SetImageSize instead of imaqSetImageSize and LV_FillImage instead of imaqFillImage (which also not a good idea, I think). Better way to use imaq* functions and perform conversion to the desired type inside of DLL or just keep everything as shown above. But anyway you should keep in mind that these ways are "undocumented", and the only officially supported way is using pixel pointer. But passing image directly to DLL will keep Block Diagram more clear.
With IMAQdx I also got some troubles in the past with GigE Vision camera because NI-IMAQdx High Performance GigE Vision Driver was replaced with the driver from camera supplier. If you have performance issues - be sure that this driver is installed and used (assumed that you have GigE Vision camera).
01-16-2020 01:25 PM
But from C language point of view, you passed in a structure, and used only one component of the structure, why not simply pass in that component by itself?
All the function calls are used on the image (which is created in the dll) not on the structure.
Only one line of code related to the structure:
LV_Image->address = image;
By the way, image structure works. Kudos.
01-27-2020 03:50 PM
I don't know about IMAQ specifics but it looks to me like you may not be handling the pointers correctly.
Your function prototype is expecting a pointer to some Image data but instead of manipulating the data image is pointing to, you are completely replacing the pointer. At a high level, LabVIEW is passing address A and then you are locally creating an image with address B and filling that image. Those functions can work exactly as advertised (hence no errors returned) but when we return to LabVIEW we look back at address A (what we passed to the function) and see an empty image.
01-27-2020 07:48 PM
It's very IMAQ specific.
The input pointer has no data. Because I don't know the image type or size, I can't create the image in LabVIEW.
01-29-2020 08:39 AM
If that's what you're looking to do you would probably want the parameter to be a pointer to the image pointer then right? That's more or less what the struct gives you as far as I can tell (the LV cluster is not exactly handled that way in memory but it ends up working itself out).
01-29-2020 10:06 AM
> If that's what you're looking to do you would probably want the parameter to be a pointer
> to the image pointer then right?
What the parameter are you referring to? I don't know the image size or type in LabVIEW. And I don't want them return to LabVIEW. I have only one input: the pointer to an image(Image *image).
01-29-2020 08:11 PM
@zou wrote:
What the parameter are you referring to? I don't know the image size or type in LabVIEW. And I don't want them return to LabVIEW. I have only one input: the pointer to an image(Image *image).
I was talking about the image parameter of the TestImage function. I'm also assuming in your original post that you are expecting to look at the image pointer in LabVIEW after the function has executed and find that it is a 100x100 gray image so let me know if that is not correct.
If that is what you would be expecting then I don't think the C function is set up correctly. You are passing in a pointer to an image, basically an address to some memory location that should hold the image. If I'm reading everything correctly then imaqCreateImage will create a new image pointer (different address to a different memory location) that replaces image and then that new image is set to size 100x100 and filled with grey. When we return to LabVIEW we will be looking at the original pointer passed to the function only to find out that it is still empty because we were operating on a completely different image.