Stop program after image closes

3 ビュー (過去 30 日間)
Adrian Lim
Adrian Lim 2018 年 6 月 28 日
コメント済み: Adrian Lim 2018 年 6 月 28 日
w = webcam;
while true
img = w.snapshot;
imshow(img) % display the image
pause(0.1); % pause for one second
end
This program allows me to show the frames of the video per 0.1 second but it keeps on running after closing the image and the image keeps popping out. Is there a solution to let the program knows the image is closed hence terminate the program?

採用された回答

Guillaume
Guillaume 2018 年 6 月 28 日
One possible way is to create the figure before starting your loop, keep its handle and check that it's not been deleted (which will happen when you close the figure):
w = webcam;
hfig = figure;
while isvalid(hfig) %while figure has not been closed
img = w.snapshot;
imshow(img);
pause(0.1);
end
  1 件のコメント
Adrian Lim
Adrian Lim 2018 年 6 月 28 日
Thank you so much! It worked!

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by