NI Home > Community > NI Discussion Forums

Machine Vision

Showing results for 
Search instead for 
Do you mean 
Reply
Member
Neo6
Posts: 110
0 Kudos

Queues in Image Processing- Missing a very very small concept

Hello LabVIEW Folks,

 

I want to build an application where I need to set attributes to a camera and save Images. I am building this application by combining two example VI available from NI. 

 

1) For grabbing and setting attributes, I am using 'Grab and attributes setup.VI' from examples in Labview

 

2)For saving Images using producer and consumer loop, I am using concept from  http://zone.ni.com/devzone/cda/epd/p/id/5859

 

I have mixed both examples, But problem is, whenever there is an element(buffer number) in the queue, the image processing code in the case structur(1,Default case) of consumer loop has to execute (like same as VI in this link http://zone.ni.com/devzone/cda/epd/p/id/5859 ) . It is not doing so.  Where is the mistake?????????????

 

I am attaching my VI  here.

 

 

Regards

Neo.

Knight of NI
RavensFan
Posts: 15,673

Re: Queues in Image Processing- Missing a very very small concept

Your consumer loop is a greedy loop because it has nothing slowing it down from running as fast as the CPU will allow.  Also, you dequeue in the case that has zero elements, do nothing in the case that has 1 or more queue elements.

 

Try swapping your cases, and put a small wait statement in the case structure that does not dequeue.

 

(In reality, a proper consumer loop wouldn't check the queue status, it would just sit there with a dequeue element and wait for an element to arrive in the queue.)

Member
Neo6
Posts: 110
0 Kudos

Re: Queues in Image Processing- Missing a very very small concept

Hello RavensFan,

 

1) You said consumer loop is greedy and it has slow down, if so why the example in the below link is working fine in my system even without having time delay ???

http://zone.ni.com/devzone/cda/epd/p/id/5859

 

2)In the VI that I posted, I placed the deque element in 'No element Case". But my main intention is to check whether that case is executing or not. So Inside that case structure I am just counting number of times that case has executed. At present deque element dosent have to do anything in that case.

 

Heere the problem is case structure is not even executing even there is element in the queue . But the same concept works perfectly in the below example

http://zone.ni.com/devzone/cda/epd/p/id/5859

 

Where I am missing ??????

 

Regards

Neo 

Knight of NI
RavensFan
Posts: 15,673

Re: Queues in Image Processing- Missing a very very small concept

Modern CPU's with multiple processors aren't as affected by greedy loops as the days with a single processor since there is another processor to help handle the load of doing mouse and screen updates.  But it is still not a good idea to have a loop running as fast as it can unnecessarily.

 

Why would you place the dequeue element in the  "no element" case.  That makes no sense.  If you have no elements, then it will go into the case where you have the dequeue.  Then it will wait for the element.  Then when it finally gets there, the dequeue will happen, and the case and loop iteration will finish.  But if another element gets into the queue before you check the status again, then the "there is an element case" will happen.  Then that case will run on every iteration from there on out because you never dequeue the element again.

 

You programmed the cases the complete opposite of what the example did.  Which is why the example works, and your program doesn't.

Member
Neo6
Posts: 110
0 Kudos

Re: Queues in Image Processing- Missing a very very small concept

Hello RavensFan,

 

I found out the mistake as you said. Now everything is working fine. I added a time delay function in no element case.

 

 

But 1 in lets say 30 runs is still failing. Consumermer loop is still  missing some elements which are queued. I understood that  it is because of greedy consumer loop.  In this kind of greedy consumer loop case, what happening to the elements inthe queue which are not dequeued ??? 

 

Regards

Neo.

Member
LamD.
Posts: 79

Re: Queues in Image Processing- Missing a very very small concept

Hi Neo6,

 

I also took a look on your VI. The case structure in your consumer loop is a bit strange. You are only looking for 0 or 1 elements in queue. If there are more than 1 Element your consumer will stop reading data.

Just check if the elements in queue are >= 1 and then always grab your data.

 

Best Regards,

Lam

Member
Neo6
Posts: 110
0 Kudos

Re: Queues in Image Processing- Missing a very very small concept

Hi Folks,

 

By following all the guidelines in this thread, I have edited my VI (see attahment), now it is working fine. But I noticed a strange behavior with it.

 

After pressing run button , and clicking 'start grab', VI is running fine. But when I click the 'stop grab', VI is taking nearly 5 to 10 seconds to stop the grabbing process. If  I do it for the second time, grabbing process is stoping as soon as I press the 'stop Grab'(same control) button.  

 

Any clues why this is happening  ???

 

Thanks and regards

Neo.

Member
Neo6
Posts: 110
0 Kudos

Re: Queues in Image Processing- Missing a very very small concept

Hi Folks,

 

Can you anyone look over my problem,

 

By following all the guidelines in this thread, I have edited my VI (see attahment), now it is working fine. But I noticed a strange behavior with it.

 

After pressing run button , and clicking 'start grab', VI is running fine. But when I click the 'stop grab', VI is taking nearly 5 to 10 seconds to stop the grabbing process. If  I do it for the second time, grabbing process is stoping as soon as I press the 'stop Grab'(same control) button.  

 

Any clues why this is happening  ???

 

VI is attached in the previous post

 

Thanks and regards

Neo.

Knight of NI
RavensFan
Posts: 15,673
0 Kudos

Re: Queues in Image Processing- Missing a very very small concept

Are you getting an errors on the error wire when the grab button is pressed?

 

Why are you unregistering for the grap event on the first call of the Grab button becoming true?  It is somewhat of a race condition between the unregister for events and register for events node.  Which happens first is somewhat up in the air.

Member
Neo6
Posts: 110
0 Kudos

Re: Queues in Image Processing- Missing a very very small concept

Hello RavensFan,

 

I am not getting any error when grab button is pressed. I have built directly from the example 'Grab and setup attributes.VI' . To be frank I have no idea why the first event was unregistered. I am attaching the base example. Since this example was from NI, I never doubted on its working. It would be great help to me, if you can figure out why the event was unregistered.

 

Thanks and Regards

Neo