Figure gets displayed only after terminating the program. What to do?

2 次查看(过去 30 天)
im using subplots with imshow in my program which reads frames from a video file. Output figure is not getting displayed. If i terminate the program using Ctrl+C, the figure shows up. However instead of video file if I read input from webcam with videoinput, I get the output figure normally as usual. Code:
foregroundDetector = vision.ForegroundDetector('NumGaussians',3,'NumTrainingFrames',10,'LearningRate',0.000001);
foregroundDetector1 = vision.ForegroundDetector('NumGaussians',3,'NumTrainingFrames',10,'LearningRate',0.000001);
%vid = videoinput('winvideo', 1); %select input device
vid = vision.VideoFileReader('daria_walk.avi');
i=1;
DlgH = figure;
H = uicontrol('Style', 'PushButton', ...
'String', 'Close', ...
'Callback', 'delete(gcbf)');
while (ishandle(H))
frame = step(vid);
%frame = getsnapshot(vid);
YCBCR = rgb2ycbcr(frame);
rgbForeground = step(foregroundDetector, frame);
ycbcrForeground = step(foregroundDetector1, YCBCR(:,:,3));
se = strel('square', 3);
filteredForeground = imopen(rgbForeground, se);
subplot(1,2,1);
imshow(filteredForeground);
title('RGB Foreground');
subplot(1,2,2);
imshow(ycbcrForeground);
title('YCBCR Foreground');
end
close

采纳的回答

Jan
Jan 2016-2-19
Try to insert a drawnow command to instruct Matlab to update the display.

更多回答(0 个)

类别

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