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.

Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I make 1D array and pointer to place acquired image?

Solved!
Go to solution

How do I make a 1D array and create a pointer to the first position to put an image into?  I thought that was what I was doing (see attached image) but continue to get a 1097 error, likely because of the improper memory allocation.  I have the image size in bytes and a null string going in to call a dll, and am fairly sure that is not what is causing me difficulties.  However, the pData is supposed to be a pointer to the first element of a 1D array that is pixel width * height.  I read on the LV website that the image array that I have made looks like a 2D array but actually is a 1D array and that the pixel pointer points to the first element of the array.  Is that not the case?  Thanks.

0 Kudos
Message 1 of 24
(5,272 Views)

Hey jjsword,

 

The website is correct, that is a 1D array. What happens if you remove the U16 conversion in that VI? Converting that pointer to an integer may be causing the problem. Also, which .dll are you calling with that Call Library Function Node? You might want to check out this example which details how to format your calls to .dlls for various input types. We also have a manual which details interfacing with external code in LabVIEW. You might also want to make sure that your .dll isn't looking for an array handle pointer. Hope that helps!

John B.
Embedded Networks R&D
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 2 of 24
(5,257 Views)

It still gives the error without the U16 conversion.  Is there any way to convert the U32 pointer to an array data U16 pointer?  What I posted is just one of many trials in hopes to get things working.  The dll is mcammr.dll which is for the Zeiss MRm v2 camera.  They don't freely distribute the SDK so I can't share all the C documentation that they sent me.

 

I will look at the documentation you recommended and try all the different types of pointers in hopes that one works.  I do know for certain that I have to input a U16 pointer, which I assume to be array data pointer, but will check to be sure.  Thanks for the reply.

0 Kudos
Message 3 of 24
(5,243 Views)

No problem, let me know if you still have questions after checking the documentation. Have a great day!

John B.
Embedded Networks R&D
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 4 of 24
(5,227 Views)

After looking over the documentation I am still having difficulty with the pointer.  IMAQ GetPixelPointer outputs an unsigned long pointer.  The dll expects pData, an array data pointer to a length * width array of unsigned shorts, to be an unsigned short pointer.  How do I convert the U32 pointer to a U16 pointer, if that is even possible?  Thanks!

0 Kudos
Message 5 of 24
(5,222 Views)

After digging into the documentation and looking at some example files, it seems that I might not be able to get a U16 pointer for my IMAQ Image array using GetPixelPointer, since it outputs a U32 pointer value.  The camera acquisition function calls a U16 pointer to the 1D array of U16 pixels.  I was thinking that perhaps I need to just create a buffer of 1D arrays (not the arrays which IMAQ Create makes) which I can then enter into the dll for a U16 array pointer to that array.  Is there any way to connect the IMAQ Image array to a 1D array (as opposed to Numeric) pointer value on the Call Library Function Node? 

0 Kudos
Message 6 of 24
(5,213 Views)

Hey jjsword,

 

Unfortunately, on a 32-bit operating system, all pointers should be U32. There is no way that I have been able to find to convert between them. You do have a couple options though. You could write a wrapper .dll that converts your pointer to the proper format. You might also want to check the documentation of the .dll and see if there is a similar function that calls for more modern pointer handles than the function you're currently using. Hope that helps!

John B.
Embedded Networks R&D
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 7 of 24
(5,204 Views)

Thanks.  I was coming to the conclusion that I would have to write a wrapper dll or change the array type entirely from the IMAQ Image array to a 1D array.  I was thinking of perhaps dumping the images into a 1D array and then turn that into a 2D array without the help of any of the IMAQ vi's.  Seems like I could then wire the 1D array straight into the Call Library Node pData pointer and set it as a 1D array U16 value pointer.  Any reason that wouldn't work?

0 Kudos
Message 8 of 24
(5,202 Views)

That might work. It's definitely worth a shot before going to all the trouble of writing a .dll.

John B.
Embedded Networks R&D
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 9 of 24
(5,198 Views)

A pointer is always pointer-sized. There is no difference between a pointer to a U16 array and a pointer to a U32 array aside from how your entrypoint is ultimately interpreting the data. LabVIEW is not designed to have pointers on the diagram wires so there is no way to mark the type of the data that the pointer points to (unlike C/C++ where pointers traditionally can be typed). The U32 output from GetPixelPointer (or actually U64 I believe on newer versions of that VI) is storing the pointer itself----it is not referencing the type of data the pointer points to, so the type will always be >= the size of a pointer on that platform.

 

If you just mark the parameter on the call-library node as a "pointer-sized integer" you can pass the image data pointer to your DLL from the output of GetPixelPointer. The pointer will always point to pixels that are the size of your image pixel format (8, 16 or 32-bits). Thus if your image is in U16 format, the pointer from GetPixelPointer is a pointer to U16 data (a 1D array with a stride between lines if you have borders or non-32-byte-aligned lines).

 

Eric

0 Kudos
Message 10 of 24
(5,118 Views)