Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

IMAQ Flatten to String memory usage

Hi All,

 

I am working on an application where I need to simultaneously display and save two HD (1280px x 1024px) video streams. I am running into issues with my memory usage skyrocketing by about 300MB/s when I use the IMAQ Flatten to String function.

 

Initially I was simply passing the IMAQ image into the queue, but this approach was causing my frame rate to drop significantly, from about 30FPS to 15-20FPS. To remedy this, I used the IMAQ Flatten to String function. This appears to solve the frame rate issue, but, as mentioned above, the memory usage is incredibly high. The application errors out with a memory message after about 10-15sec of run time.

 

Any insight?

 

Download All
0 Kudos
Message 1 of 5
(3,217 Views)

Hi ademedeiros, 

 

It looks like the main issue you're running into is that streaming the large HD images at 30 fps is using up the allotted 3 GB of memory LabVIEW has access to. To mitigate this, there are two main options:

  1. You could potentially move to 64-bit LabVIEW, which can access much more RAM than the 3 GB 32-bit is limited to.
  2. You can try compressing the files to JPEG first before pushing them into the buffer. The IMAQ Flatten Image to String function has a Compression Type input, that you can wire JPEG compression to.  This should reduce memory footprint for your application.

Let me know if these answers make sense or if I can provide any other information!

 

Best,

Austin H.
Chief Product Manager
Test Software
0 Kudos
Message 2 of 5
(3,146 Views)

Flattening to a string is is unnecessary here and will take way more CPU than you likely want. You should follow your original design of putting images into queues. However, putting Vision Images into queues is tricky, since they are a reference datatype, not a value datatype. You have to be certain you don't reference the same image in other places. The typical Grab loop will re-use the same image each iteration, so putting that reference into a queue each time will have incorrect behavior, that may end up looking like a drop in frame rate.

 

To do this properly you really need two queues of images, one that you pull out of to pass into the grab, then queue into the second for processing. Once the processing is done, you queue it back into the first queue that the grab loop is using. This pattern ensures you are never using the image references in two places at once.

0 Kudos
Message 3 of 5
(3,141 Views)

Thanks for all of the suggestions.

 

BlueCheese, in regards to your first point, if I set "Wait for Next Buffer" in IMAQdx grab, wouldn't that prevent blank frames? I am under the impression that IMAQdx grab will wait until the next frame is available or, until the timeout runs out. 

 

Can you clarify your suggested approach? I'm having a hard time following along. If you could provide a simple barebones snapshot of an example I would be very appreciative.

 

Thanks!

0 Kudos
Message 4 of 5
(3,134 Views)

-There's nothing like Blank Frames, What happens in Grab is you get the image from camera and put that image data into the memory space created using IMAQ Create(Image Name is the reference to the memory).

-As said earlier you don't need to use IMAQ Flatten to String. The memory overflow could be because when use Flatten and Unflatten functions improperly.(you haven't provided proper code to look into exactly how memory allocations are happening)

"If an image has the same name as the flattened image in memory, when the string is unflattened, the contents of the flattened image string are copied to the image. Otherwise, a new image with a unique name is created that contains the contents of the flattened image string" from http://zone.ni.com/reference/en-XX/help/370281P-01/imaqvision/imaq_flatten_image_to_string/

-If your Writing speed is not enough you will eventually end up with memory overflow.

-Use IMAQ Create function and define user buffers(maybe 20-30) depending on how fast/slow your writing process and reuse the buffer names.

-Other way is every iteration create new buffer and dispose after writing to avi.

Thanks
uday
0 Kudos
Message 5 of 5
(3,118 Views)