05-10-2021 09:36 AM
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:
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.
Solved! Go to Solution.
05-10-2021 01:18 PM
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.
05-17-2021 07:22 AM
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.
05-18-2021 01:53 AM
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.
05-18-2021 01:54 AM
Hello, it was a labview error indeed, sorry for the trouble.
05-18-2021 03:58 AM
Ok, glad to see you've solved your problem!
05-18-2021 04:20 AM
@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.
05-18-2021 05:27 AM
Yes, I meant that actually, it was my mistake. 😅