Example Code

Image Streaming to Binary File (with Backlog)

Code and Documents

Attachment

The attached code shows two different LabVIEW coding architectures for streaming IMAQ images to a binary file. One VI uses a Producer-Consumer loop design pattern, while the other uses a Single loop design pattern. The Producer-Consumer architecture has the added benefit of using a queue system to transfer data from the image acquisition loop (producer) to the processing loop (consumer). The Single loop architecture is slightly less complex and is a good starting point for less-experienced LabVIEW users.

In general vision applications, if image processing takes longer than image acquisition, then it is inevitable that an error or unexpected behavior will occur. A "backlog" will be present when this happens, meaning that the processing portion of the code lags behind the acquisition portion (e.g. buffer #40 may have just been acquired and transferred to memory, but the code is still processing buffer #25). The backlog in these examples is not meant to prevent such behavior from happening, but serves as an indicator to the user that eventually a buffer overflow could occur.

With its queue system, the Producer-Consumer VI has the added benefit of never missing any frames while streaming images to disk, even when a backlog occurs. This is not something that is guaranteed in the Single loop architecture. Both VI's can simulate the backlog by a user-modifiable "Delay" field on their respective front panels. Begin incrementing the delay from 0ms until you see the backlog slowly rise, indicating the processing lag.

Once the acquisition has completed, the binary file that was created can be read back with the Read Binary File from Disk VI.

Steps for Using the Code

  1. Download and extract the attached zip file.
  2. Open the main project file, Image Streaming Project.lvproj
  3. Underneath the My Computer heading, launch either Producer-Consumer Stream to Disk.vi or Single Loop Stream to Disk.vi.
  4. Enter the correct information in the controls and file path fields on the front panel.
  5. Run the VI. Stop the VI when ready.
  6. Open Read Binary File From Disk.vi and point to the correct file path for the binary file to display the image frames.

Please refer to the comments within the block diagrams for more information about the code.

Please Note: Currently, the example is only written for IMAQ image acquisitions. Code for IMAQdx-based acquisitions will come soon.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
auroraSun
Member
Member
on

I am trying to convert binary files to RGB(U32) movie files after I saved the binary files with a web cam.

 

Since the USB webcam is a color camera, I can see color images on the screen. But the files saved and read by the example code show grayscale movies. The comments in the example vi says that, currently, the example is set up for U8 images only. I tried to make some changes to save and read U32 files but couldn't make that work. I thought just changing data type from U8 to U32 for Image Data Array would do the job. But, it seems to be more than that because that didn't work. Looks like I miss something here.

 

Could anyone help me find out what I need to add to save and read color movies RGB(U32) other than grayscale(U8)?

 

Thanks a lot!!

Contributors