Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

De-queue Question

Hi All, I'm trying to use Producer-Consumer structure to get the highest throughput from a camera (60fps). Once the image was acquired in the producer loop, it is en-queued and sent to a consumer loop. In the consumer loop, it is de-queued and do the processing. However, I met some problem when the producer loop is configured as a state machine. The en-queue is confirmed to work as expected, but the de-queue in the consumer loop does not get any image output. The en-queue gets overflowed very quickly and none image was de-queued from the consumer loop. The screen shot was saved as 'Dequeue Problem.png'. As a comparison, if I use a simple loop rather than a state machine in the producer loop, everything works properly. I'm confused by the above two solutions and try to understand where the problem comes from. Can anybody give me a hint? Thank you for your help in advance. Regards, JJ
0 Kudos
Message 1 of 4
(1,945 Views)

You should be careful with producer/consumer pattern when using it with IMAQ images. In general the IMAQ images stored by reference and not by value, it means that in your case all images in the queue will point to the same image.

You have in general two possilities. The first obvious solution is to convert images to the arrays and enqueue arrays instead of native IMAQ images. In this case you will get "conversion penalties". You can use this way if this acceptably from performance point of view. Another way (which is more elegant) is to create array of the IMAQ images, using "ring acquisition".and limit size of the queue to the size of the array to be sure that the image under procession in the consumer loop will never be overwritten with producer loop.

 

with best regards,

 

Andrey.

0 Kudos
Message 2 of 4
(1,913 Views)

Hi Andrey,

Thank you for your advice. I've tried two ways based on your comments.

1) make an image copy and then en-queue

2) convert the image into a 2D array and then en-queue.

However, both ways did not work. The de-queue does not work at all, just like before. I've attached the raw vi here for your reference.

 

I've also attached a screenshot by using a simple look for the en-queue, where in such a case the whole system work smoothly and as we expected.

 

Thank you and look forward to your reply.

Cheers,

JJ

Download All
0 Kudos
Message 3 of 4
(1,841 Views)

Hi,

You should perform copy in the acquisition loop and not in processing loop, otherwise you sztill have a problem that the different elemnts in the queue are referred to the same image.

Let me explain what happened.

At the first I will create pretty simple Producer/Consumer example. "For" loop acts as producer, send every 20 ms one image to the queue. "While" loop is consumer, where some processing is done. I will fill the image with constant gray value and will check this gray value in the processing loop. What I expect - that the every buffer will get intensity equal to the number of the buffer:

So far it works:

demo0.png

But now I will delay processing loop for 100 ms for every 10th image:

demo1.png

What happened now? Now I will get different buffers with same values:

demo1w.png

This happened, because buffers 1,2,3,4,5 are filled with same image, because the IMAQ images stored by reference - they referred to the same image. When processing cycle is not fast enough, then acquisition loop sends 5 queue elements, and when processing loop is able to process, then the image which is just acquired in this moment is processed - there is no copy in queue, just reference.

 

What can I do? I can transfer images as arrays instead of native IMAQ images:

demo2.png

As result I have performance penalties for conversion to and from array, but it works without collisions, because each element in the queue filled with proper data (and holds a copy of the acquired image).

 

Another way is transfer images as native IMAQ images, buth then you have to limit size of the queue and do it with ring buffer, something like that:

demo3.png

Now result back to expected:

demo3o.png

 

Hope it helps for understanding.

with best regards,

Andrey.

 

0 Kudos
Message 4 of 4
(1,824 Views)