Effacer les filtres
Effacer les filtres

i am using red object detection program,but the prb is i am unable to stop/interrupt the program when its running,plz help me

2 vues (au cours des 30 derniers jours)
if true
% codevid = videoinput('winvideo', 1, 'YUY2_640x480');
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 1;
start(vid)
while(vid.FramesAcquired<=50)
data = getsnapshot(vid);
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
diff_im = medfilt2(diff_im, [3 3]);
diff_im = im2bw(diff_im,0.18);
diff_im = bwareaopen(diff_im,300);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
imshow(data)
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
end
hold off
end
stop(vid);
delete(vid);
end
the program only stops after 50 frames are captured,i dont want to change it, but i should be able to force stop it at between, what is the code for it??

Réponse acceptée

Image Analyst
Image Analyst le 17 Avr 2013
You can have a checkbox on your GUI that says "Finish now" and then you check it in your while or for loop. If the checkbox is set, you break out. Put this in one of your loops, wherever you think it's appropriate.
if get(handles.checkboxQuit, 'Value')
break;
end
  7 commentaires
dwaipayan chakraborty
dwaipayan chakraborty le 9 Mai 2013
Here's what worked for me. After using ctrl-c, if it says that the camera is still in use, just type the following in the workspace :
stop (vid)
delete (vid)
Image Analyst
Image Analyst le 9 Mai 2013
Yeah, kind of like stopping your car by throwing a lug wrench into the serpentine belt instead of turning the ignition key off.

Connectez-vous pour commenter.

Plus de réponses (2)

Walter Roberson
Walter Roberson le 17 Avr 2013
The closest you might be able to get without changing that code, would be an arrangement to error out of the program. MATLAB is not designed to be able to force a loop to quit without the cooperation of the loop.
  1 commentaire
vishnu andavar
vishnu andavar le 18 Avr 2013
i am ready to add new code in my program to get out of loop,so what do u think is best code to exit out and i can resume later without the matlab saying "camera already in use ?"

Connectez-vous pour commenter.


tairman singh
tairman singh le 18 Avr 2013
Add this into your while loop
k=get(gcf,'currentkey');
if (k=='s')
disp('program stopped')
break
end
and when you press 's' in keyboard you'll be able to get out off the loop and also place these before end flushdata(vid) delete(vid) imaqreset close all clear all
Hope it'll help i'm having the same problem
  2 commentaires
vishnu andavar
vishnu andavar le 22 Avr 2013
its not working ,when i press "s" it just displays s on matlab that's it
tairman singh
tairman singh le 3 Mai 2013
keep pressing it until it breaks out of loop or put pause(0.2) before these commands.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by