2017-03-23 11 views
0

フォアグラウンドディテクタを使用してビデオにバックグラウンドの減算を適用しようとしています。バックグラウンドの減算は機能しますが、imshowは最終フレームのみを表示します。すべてのヘルプは、あなたが継続的にグラフィックがループ内でオブジェクトを更新する場合は、明示的なdrawnowの実行中に一時停止ですがあるまで、グラフィックスが実際にレンダリングされていない、不要なグラフィックス処理を防ぐためにimshowの最後のフレームだけが表示されます

foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...'NumTrainingFrames', 100); 

videoReader = vision.VideoFileReader('test1.mp4'); 

for i = 1:120 
    frame = step(videoReader); % read the next video frame 
%  imshow(frame); 
    disp(i); 
foreground = step(foregroundDetector, frame); 
    imshow(foreground); 
end 

答えて

0

をいただければ幸いですイベントキューを強制的にフラッシュするために使用されます。サイドノートとして

for k = 1:120 
    frame = step(videoReader); % read the next video frame 
    foreground = step(foregroundDetector, frame); 
    imshow(foreground); 

    % Explicitly force the renderer to update the display 
    drawnow 
end 

、パフォーマンス向上のためにするのではなく、絶えずimshowで新しいものを作成するよりも、既存の画像オブジェクトを更新する必要があります。

frame = step(videoReader); 
foreground = step(foregroundDetector, frame); 
him = imshow(foreground); 

for k = 1:119 
    set(him, 'CData', foreground) 
    drawnow 

    frame = step(videoReader); % read the next video frame 
    foreground = step(foregroundDetector, frame); 
end 
関連する問題