Matlab slows down while plotting a figure.

6 views (last 30 days)
Aravind
Aravind on 26 Oct 2014
Commented: Jan on 3 Oct 2017
I'm coding an algorithm for lane detection,
This is the skeleton code I've used,
while ~isDone(video){
currentFrame = getFrame(video);
.
. % Do segmentation and lane detection
.
figure(1),imshow(currentFrame),hold on
figure(1),plot( theLinesThatWereDetected );
pause(.0001); % without pause the plot command wouldn't work like a streamer.
}
This is a video of the simulation, Simulation
Problem : The output video gets slower and slower after displaying each frame, but as soon as I close the figure window it automatically restarts(as the code's running) and it gets faster(check video). Why is this happening, is there some memory build up that is happening to slow down the plotting? What can I do to fast things up other than manually closing figure window?
I know there is a video.ShapeInserter object available which is faster than the plotting method I've used . The reason I didn't use it is because the changing the thickness of lines in thee video.ShapeInserter object came only in the 2014 release and I'm using 2013 version. I wanted very distinct thick lines for my lane detection.
Kindly give me suggestions.

Answers (1)

Jan
Jan on 27 Oct 2014
Edited: Jan on 27 Oct 2014
Do you add a new plot in each iteration, e.g. triggered by a hold? Or do the plots repalce the former plots?
Anyway, it is cheaper to change the XData and YData of an existing LINE-object, which was ceated by plot(). A large number of objects in a figure slows down the processing meassively.
Search in the forum for "plot xdata" to find examples.
  3 Comments
Chang Liu
Chang Liu on 2 Oct 2017
I'm faced the same problem, wondering if anyone can give me a clue here, I think the RAM is just rocketing with too many objects.
Jan
Jan on 3 Oct 2017
The last statement of Aravind was: "But didn't work the way I wanted". I cannot guess, what was wanted and how it differs from the results.
Now you explain, that you have "the same problem". Please give us a chance to answer and post any details. What is your code, what do you observe and what is your question? The best would be to open a new thread.

Sign in to comment.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!