LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing an IMAQ Image to DLL

Solved!
Go to solution

Hello, I am trying to pass my image to my dll library but could not work it out up to now. Here is my dll source code:

berkay123_1-1620657059601.png

I tried to change the code for the given Copy_C_Image_To_LabVIEW_Image dll function in the help section of IMAQ GetImagePixelPtr VI, although the original code did not work out for me as well. I want to pass an image and create the same image (if it is possible) then change its RGB values. Any help is appreciated. You can see the .vi file in the attachment.

 

0 Kudos
Message 1 of 8
(2,034 Views)

Hello, can you add some detail more on your scenario?

I'm not an expert in IMAQ and image processing, but reading your post I cannot understand if your problem lies on the LabVIEW side or elsewhere.

Are you using CVI at all? You ended up posting your question in the CVI board but you attached a LabVIEW VI so it's not clear. If CVI is involved, please tell us which release you are using and that of the associated libraries.

When you say that the code (both original and modified) does not wotk for you, it means you are receiving some error? If so, which one and where in the code?

 

 

If eventually you think this post should be moved to the LabVIEW board you can notify the moderators asking them to move it for you.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 8
(2,001 Views)
Solution
Accepted by topic author berkay123

This definitely is mostly a LabVIEW problem, even though you try to do some C code development. So you should ask to have this thread transferred to the LabVIEW board. Your code has many more or less serious problems.

 

First the two image pointers are not strings but should be configured as pointer sized unsigned integer in the Call Library Node.

 

Second, IMAQ Create by default will create a 0*0 pixel, 16-bit grayscale image. Then IMAQ Read File will convert that to whatever image format fits best with the image you try to load, which for standard Windows files except maybe TIFF files sometimes, will definitely never be a 16-bit grayscale image. Then you correctly set the size of the target image to the same height and width as the source image, but you do not change the pixel format accordingly. What now most likely happens is that your source image is a x * y 24-bit or even 32-bit RGB image, while your target image still is a x * y 16-bit grayscale image. So the created image buffer for the target image is potentially only half as big as your source image.

 

Third the line width returned from IMAQ Map Pixel Pointer is in Pixels not bytes but you pass it to the DLL functions unaltered and treat it inside as if it were bytes. The length parameter for memcpy() always works in bytes.

 

Then you go into the C code and try to copy the larger image buffer into the smaller => Perfect memory corruption from classical buffer overrun error!

 

Unless you make 100% sure that all the attributes of source and target image are the same (that includes pixel format, border size, height and width, you can not blindly copy images from one to the other but have to consider that the line stride (the line width * bytesPerPixel) can be different for two images, and if the pixel format is not exactly the same you even have to do conversion of each pixel between the two color formats.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 8
(1,964 Views)

Hello rolfk, thank you for your time, indeed it was a labview problem, and you are right I managed to change all of these, thank you again.

0 Kudos
Message 4 of 8
(1,945 Views)

Hello, it was a labview error indeed, sorry for the trouble.

0 Kudos
Message 5 of 8
(1,943 Views)

Ok, glad to see you've solved your problem!



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 8
(1,940 Views)

@berkay123 wrote:

Hello, it was a labview error indeed, sorry for the trouble.


I see no error here in respect to LabVIEW 😀. More correct would be to say it was your failure to treat the functions correctly.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 8
(1,928 Views)

Yes, I meant that actually, it was my mistake. 😅

0 Kudos
Message 8 of 8
(1,916 Views)