Displaying figures in a while Loop

4 views (last 30 days)
Ryan
Ryan on 19 Oct 2015
Answered: Walter Roberson on 20 Oct 2015
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........

Answers (1)

Walter Roberson
Walter Roberson on 20 Oct 2015
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()

Categories

Find more on Startup and Shutdown 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!