Example Code

Community Example: IMAQdx Ring Buffer Producer to Processing Consumer

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • Machine Vision

    Software

  • Vision Development Module
  • LabVIEW

    Driver

  • NI Vision Acquisition Software

Code and Documents

Attachment

Overview

The example demonstrates how to perform a buffered acquisition and write frames to a AVI file.

 

Description
This example demonstrates a low-level IMAQdx acquisition that uses a configurable number of buffers for asynchronous operation.
The image frames are subsequently saved to a AVI file. Since the low-level function of IMAQdx already features buffering no additional buffering is required.

 

Requirements

 Software

  • LabVIEW 2012 Base Development System (or compatible)
  • Vision Development Module 2012 (or compatible)
  • NI-IMAQdx 4.0 (or compatible)

 Hardware

  • NI-IMAQdx compatible hardware

 

Steps to Implement or Execute Code

  1. Select a new or existing file to write the AVI file to
  2. Select a camera and adjust the 'Frames Per Second' setting to match the camera
  3. Run the VI

 

Additional Information or References

IMAQdx Low-Level Acquisition and AVI Write LV2012 NIVerified.vi - Front Panel.png

 

IMAQdx Low-Level Acquisition and AVI Write LV2012 NIVerified.vi - Block Diagram.png

 

Remark:
A previous version of this example used a queue to store images to use a producer consumer pattern. The problem with this approach is mainly that not the images themselves are buffered but merely the references are buffered in the queue.
So in case the image buffer is overwritten in the maintime, the program can not detect that and therefore produces a false sense of security.
Since the low-level IMAQdx functions already offer buffered acquisition no producer consumer pattern is necessary.

 

What Is the Difference Between NI-IMAQ, NI-IMAQdx, and NI-IMAQ I/O?
http://digital.ni.com/public.nsf/allkb/0564022DAFF513D2862579490057D42E

 

**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text 'NIVerified'. Read here for more information about the new Example Guidelines and Community Platform.**

Paolo F.
National Instruments
Applications Engineer

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

Comments
hanson_chc
Member
Member
on

But if the producer grabs images far faster than the consumer, the buffer will always be full. How to slove this situation?

Stephen1995
Member
Member
on

Did you solve this problem? I'm about to implement this code into an application that I'm building and can see this being an issue. My initial thought is to simply time the producer to ensure that the consumer can keep up but I'm not sure if this will be adequate.

Thanks

Stephen

Labview 14.0, Labview 12.0
CLAD
Mechanical Engineering Student
adrrienc
Member
Member
on

My problem using a similar structure is that with a high quality (around 950-1000) the playback video will be read too fast (in reality it is recorded too slow). I record 1000 frames at 30 fps (camera set to 30 fps, as well as AVI file). I use MJPEG codec. I can see that the processed fps is low while recording, around 23-24 fps. The created video file is 33s, which is entirey correct (1000f/33s=~30 fps). Therefore video seems to be played fast.

I try to understand where the bottleneck is. I though that by using parallel loops (producer/consumer + queue) the processing would run on its own indenpendently of the producer. It seems this is not working in this way. The only way to tackle this problem was to adjust the quality on Create AVI file VI. This is quite unclear what this quality is though. I also checked elements in the queue with Get Queue Status VI, and it seems the number of elements in it is stable and close to 0.