Image Processing Loop Crashes - Memory

Hi, I'm coding a program that captures a image from my webcam and threat it through a function 'IsolarBola', which applies a HSV filter in the image to isolate the yellow color in the image, continually. The problem is that after a while the program is running, it crashes, saying that Matlab Run Out of Memory. I'd like to know how could I fix this memory problem. Also, I'd know how to make the loop in the program 'while(camera1.FramesAcquired<=10000' just stops when I press a button, instead of with the condition 'FramesAcquired'. Thanks in advance for the help.
Here's the code of the program(sorry for the comments in portuguese):
%declaração das câmeras
camera1 = videoinput('winvideo',1,'YUY2_160x120');
%define as propriedades do video
set(camera1,'FramesPerTrigger', Inf);
set(camera1,'ReturnedColorSpace','rgb');
%inicio da captura de dados das câmeras
start(camera1);
%Inicia Loop que para depois de 200 frames adquiridos
while(camera1.FramesAcquired<=10000)
%pega uma foto do frame atual
data1=getsnapshot(camera1);
%Função para Isolar a bola e exibir a imagem da câmera
IsolarBola(data1);
end
%para a aquisição de vídeo
stop(camera1);
%limpa a memoria
flushdata(camera1);
%limpa todas as variáveis
clear all;
sprintf('%s','Fim da execução do programa');

 采纳的回答

Image Analyst
Image Analyst 2012-3-25
Look up the keyboard() function.
How are you displaying your images? Try putting "cla reset" before your imshow(). If you don't, all those images end up in the control which uses up lots of memory.

2 个评论

Thank you very much.
"Cla reset" worked for me. I'm using imshow() and it improved the memory problem, but the program still crashes after 9 minutes running.
Also I still wanna know how to change the loop conditional from "FramesAcquired" to "when I press some button".
Any ideas?
Didn't keyboard() work? Disclaimer: I've never used the keyboard() function myself. Another option that I do use is to have a checkbox on my GUI that says something like "Finish now." The GUI doesn't seem to let you run a button's code (for some reason) to set a flag to finish immediately, but it will let you check a checkbox. So I keep the checkbox hidden until my loop starts, then I show my "Finish now" checkbox so the user can click on it if they want. Then if they click on it (and I "break" out of the loop), or if the loop finishes normally, I re-hide the checkbox to make it invisible again. Anyway, that's the tactic I use.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by