Displaying figures in a while Loop

6 次查看(过去 30 天)
Ryan
Ryan 2015-10-19
Hi everybody,
I'm trying to run a while loop only when I'm receiving video from a webcam, and then stop the while loop when I manually 'x' out of the figure of the video feed. The way I'm currently doing it I always get an error when exit out of the video figure, and I've only figured out how to do it for a specified amount of time. Please help..
My current code is like this:
Video = videoinput('winvideo',2);
set(Video,'FramesPerTrigger',Inf);
set(Video,'ReturnedColorspace','grayscale');
start(Video)
while(Video.FramesAcquired <= Inf)
data = getsnapshot(Video)
imshow(data)
%AND SO ON........

回答(1 个)

Walter Roberson
Walter Roberson 2015-10-20
Video = videoinput('winvideo',2);
set(Video,'FramesPerTrigger',Inf);
set(Video,'ReturnedColorspace','grayscale');
start(Video)
imhand = imshow(zeros(2,2)); %establish an image object
while(Video.FramesAcquired <= Inf)
data = getsnapshot(Video)
if ~isgraphics(imhand); break; end %image gone, user must have deleted it
set(imhand, 'CData', data);
end
stop(Video);
If you are using R2014a or earlier, replace isgraphics() with ishandle()

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by