LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

while loop very slow and NI vision

Hi,

 

I'm programming a software using NI vision. I have registered a video of 10min, with an object that I want to track. I want to register the position (and some others informations) of my object in an excel file.

To do this, I use a while loop with shift register. During one iteration I use IMAD count objects 2.vi and I save the position in an array, and this array goes in my shift register for the next image.
But my software is very slow after 2000 frames analyzed... and it's worst after!
At the beginning of my while loop, I put an array with 40 000  "0" in order to allocate more space in memory but I have always the same probleme...

Please, I need your help 🙂

0 Kudos
Message 1 of 11
(4,309 Views)

@Paul Brugier wrote:


Please, I need your help 🙂


Please, we need your VI.  Unless you want a bunch of random guesses as to what might be wrong.  Smiley Wink

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 2 of 11
(4,307 Views)

I'm using Labview 2010 SP1.
I give you an image on my main VI. I can't give you the real VI because there are lot of subvi. Moreover I have put comments where I thought it could be useful. Sorry for the size of my VI 😕

0 Kudos
Message 3 of 11
(4,302 Views)

Just a question, how does the rest of your 6 frames stacked sequence structure look like ?

 

If anyone should be able to help you, I think you need to zip your hole project and attach it here.

It looks very overcomplicated. 

 

How long time have you been working with LabVIEW?

0 Kudos
Message 4 of 11
(4,285 Views)

I'm learning with Labview: I have started 1 year ago.
I can't give you all the files because this project is for an internship in a company. But in the others frames there are no probleme and it works fine.
I hope you could help me with only this picture 😕

 

As I said before, the software works fine at the beginning of the while loop. After one or two thousand iterations, the software is very slow.
I think it's maybe the shift registers. What do you think about it?
At the beginning of each loop, I copy the current frame: I think it's a very long task, because before I used this copy of image in the middle of the loop and I had some problems with this.

I have another question: I make a mask and put it on my copy of image. But the object after the mask is smaller than the original object. So when the pixel of my mask is different to 0, labview ignore it or Labview does a mean between the pixel value of the mask and the image? 

 

Thank you very much 🙂

0 Kudos
Message 5 of 11
(4,259 Views)

Smiley SurprisedSmiley Surprised  Oh God!  My EYES!!!

 

Well...  It could be anything.  Your program structure has obviusly grown by attrition and it's time to "byte" the bullet and re-structure into a state machine or something. 

 

If you have a high level of LV that includes VI profiling (look in Tools) you might be able to focus in on a memory leak or other obvious problem.  Otherwise you're going to have to break that mess into managable chunks (we call them SubVIs Smiley Wink) you can properly analyze, modify and re-use.  It's a pain to do, but it's worth it in the long run. 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
Message 6 of 11
(4,238 Views)

I suspect that your while loop is consuming too much memory and you are running into memory allocation issues. LabVIEW will handle memory for you however you can still write code that will cause LabVIEW to start thrashing. When working with either large amounts of data or loops with lots of iterations it is easy to chew up all the memory on the system. Your code will start to hit performance issues as it starts to try and manage those large amounts of memory. Even though LabVIEW handles the memory for you you still have to be careful how you code some things.

 

As to what specifically your code is doing I gave up trying to analyze it. Put quite bluntly your code is a mess. (I have seen worse but this is still a mess.) As stated above you should consider using a state machine. Stacked frames as well as frame in general should generally be avoided. You have very little control of the program once it enters a frame structure. State machines are much easier to maintain and you have far more control over your program's execution.

 

You have quite a few shift registers in this loop. I would look at what they are holding and which ones could be continually growing in size. A quick look at the task manager will let you know how much memory you are using. If you see the memory ever increasing you probably have a shift register that is chewing up the memory.

 

Restructure your code first and foremost. That will help you isolate where things are going awry.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 7 of 11
(4,232 Views)

Thank you very much.
I'm cleaning my VI and I'll post it soon as possible

0 Kudos
Message 8 of 11
(4,230 Views)

Hi,

 

I have cleaned my VI (Maybe it's not enought :/)
I have checked my memory with the task manager of Windows, and it looks good: It's at 70 000Kb at the beginning and 90 000Kb at the end.

I have put some counters to see the time of the 2 bigger sequences in my while loop. The first one is when my software open the frame and copy it: This task is constant during all the process (60ms).
For the second sequence, where I do some task on my image, like threshold, count object... this part takes more and more time (20ms at the beginning, 40ms at the 4000th frame...And I have around 16 000 frames in total).

I have measured the time in my subvi "Save in arraies" and the time is very short and constant (around 0.5ms).

 

So I think my problem is in the second sequence of my VI 😕

 

I attach my main VI and the subVI Mask Creator

Download All
0 Kudos
Message 9 of 11
(4,203 Views)

I think your task for this project is to remove 95% of your sequence diagrams

By the look of testRIOd.png, you are not following the dataflow.

Follow the dataflow, and you can remove some of the sequence diagrams.

 

Again take the time now to draw a design for your program. I think this will help you a lot.

0 Kudos
Message 10 of 11
(4,190 Views)