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: 

Using .DLL file/ Call Library File to Obtain Image Data from USB Camera

Solved!
Go to solution

Hello,

 

I am new to using library files and imaging data. Attached is an image of the "Call library File". I don't know how to set up the "buf" input/ frame buffer. 

 

More info is explained in the attached PDF.

 

Basically I just need to grab the image data and convert it to an actual image. I searched LabVIEW help files and other sites but I can't find a clear solution. Any help would be appreciated.

 

FYI - I can communicate with the camera using other library file functions. The camera opens, I can set/view ROI and other data. I just cant figure out the frame buffer.

 

-griplegraple

0 Kudos
Message 1 of 12
(3,210 Views)

Please, if you're going to attach an image of LabVIEW code, make it easy and use a standard graphics format (PNG, JPG, GIF) that you can embed directly in your post.  Don't take a screenshot and then post it into a PDF.  You can get a PNG image directly from LabVIEW by selecting the relevating portion and choosing Edit->Creating VI Snippet from Selection.

 

To pass in the buffer, use "Initialize Array."  Wire a U8 to the type input, and the desired array size to the size input.  Wire the array output to the call library node, configured to accept that parameter as an array of unsigned char.

 

Message 2 of 12
(3,207 Views)

Hey Nathand,

 

Thanks for the info, I will try the U8 in the type input. 

 

Didn't realize the PDF was a bad idea...  I will use VI Snippets from now on. 

 

mr. griplegraple

0 Kudos
Message 3 of 12
(3,200 Views)

Hey Nathand,

 

you mentioned "Wire the array output to the call library node, configured to accept that parameter as an array of unsigned char." 

 

The original "buf" is a string (format: C-String Pointer). In the Call Library Function, I tried to change "buf" to an array of unsigned char, but I don't see that option. I changed to the following:

 

Type=Array

Data Type: Unsigned 8-Bit Int

Array Format: Array Data Pointer

 

In string, there is not an array option. Unless I don't understand char, how to I change into the unsigned char array?

 

Thanks again,

 

-griplegraple

 

 

0 Kudos
Message 4 of 12
(3,182 Views)

I think you are misunderstanding char - a char is an unsigned 8-bit integer.  A C string is just an array of chars, and a pointer and an array are basically the same thing in C.  So, even though the function is declared as accepting a string, you can pass it an array of 8-bit integers and get identical behavior - and an array of 8-bit integers is a more useful format for handling the data in LabVIEW.  The way you described configuring it is exactly right, and there's no need to deal with strings at all.

Message 5 of 12
(3,177 Views)

Dear Nathand,

 

Thanks for the clarification. I still don't get any response, but LabVIEW keeps crashing. I think I am not initializing properly.

 

The "frame buffer" (array of 8-bit unsigned int), needs to be large enough to hold the image data. Currently I set up a 1-D array and tried different values for the size, but LabVIEW crashes. Most likely this is a memory problem and I am initializing incorrectly. 

 

Any idea on how to properly initialize this array for an image (around 800x500 res.)?

 

If we can figure this out, you will get some kudos.

 

-griplegraple

0 Kudos
Message 6 of 12
(3,170 Views)

Can you post your code?  According to your original post, the length of the array should be (width*height*bytes*Color Channel) but I have idea what the value of "bytes" and "Color Channel" are.  Are you using initialize array to create the array before passing it to the DLL?

Message 7 of 12
(3,167 Views)

Attached is the code. 

 

Again, I changed the original "string" in the library function to an "array of unsigned 8-bit int" as mentioned above. 

 

Also, Color Channel will be = 3 for R,G,B

And I am using 8 bit so bytes = 1.

 

 

Download All
0 Kudos
Message 8 of 12
(3,165 Views)

Try changing the debugging level to "Maximum" in the Call Library Function Node setup and see if that catches the crash.

Do you have any documentation about this function, or sample code written in some other programming language?  Why did you pick 1million elements?  There should be a way to determine the correct size of the array.

Message 9 of 12
(3,154 Views)

OK, so I was able to get a crash report once. 

 

"The method in the DLL overwrote pas the end of space allocated for one of its paramters. This may have corrupted memory".

 

I chose 5668704 as the number of elements since the image is 1944x972, 8 bit, 3 color channel. (1944*972*3=5668704).

 

There are portions of sample code written in C++ but they are not very helpful. Many functions are missing and not explained. 

 

I used IMAQ Array to Image.vi and I am able to get a black image. But after I run the program for a few seconds it crashes again. I probably need to set up a buffer that only keeps 1 image/frame data at a time and dumps the old image? Do you think that would stop the crashing?

 

Thanks, for the help. progress has been made. I won't be able to post back until later. I appreciate your time and effort. 

 

-griplegraple

0 Kudos
Message 10 of 12
(3,149 Views)