Take images from webcam in every second

13 ビュー (過去 30 日間)
Golshan Siyahatshayesteh
Golshan Siyahatshayesteh 2022 年 1 月 18 日
編集済み: Max Heimann 2022 年 1 月 18 日
Hello everyone,
I am trying to take 1000 images exactly in 1000 seconds, but my attached code can take just 870 photos in 1000s, which is wrong.
There must be some problem with the code. Can some one help please.
Best
clear all;
close all;
clc;
w = webcam;
t0 = clock;
tic
while etime(clock, t0) < 1000
img = w.snapshot;
file_name_save= sprintf('%f.png',toc);
imwrite(img,file_name_save)
pause(0.5)
end
toc
clear camObject;

回答 (1 件)

Max Heimann
Max Heimann 2022 年 1 月 18 日
編集済み: Max Heimann 2022 年 1 月 18 日
How are you keeping track of the 1 second intervals?
Maybe the process of taking the image and storing it takes longer than .5 and then the code pauses for another .5 seconds resulting in too few images.
Try calculating the pause time dynamically.
w = webcam;
t0 = clock;
secondsPassed = 0;
while etime(clock, t0) < 1000
secondsPassed = secondsPassed + 1;
img = w.snapshot;
file_name_save= sprintf('%f.png',toc);
imwrite(img,file_name_save)
% calculate the remaining time until the next image shall be taken.
time2wait = secondsPassed - etime(clock,t0);
pause(time2wait)
end
clear camObject;

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by