How to capture frame (image) using webcam at specific time interval (e.g. at 100ms or 10 frames per second) in matlab app designer?
3 ビュー (過去 30 日間)
古いコメントを表示
One state button is starting the webcam camera and I am previewing the video camera output in the UIAxes.
function StartCameraButtonValueChanged(app, event)
value = app.StartCameraButton.Value;
app.Camera = webcam(value);
if value == true
app.frame = snapshot(app.Camera);
app.captureCurrentVideo = image(app.UIAxes, zeros(size(app.frame), 'uint8'));
preview(app.Camera, app.captureCurrentVideo);
end
end
Now, i want to capture and store (in variables) only 10 frames per second (in the loop) from the webcam at every seconds, to get histogram of it and update the UIAxes2 to see the liv ehistogram of 10 images per seconds, how can i modify or add some code to perform this task ?
0 件のコメント
採用された回答
Eric Delgado
2022 年 10 月 5 日
編集済み: Eric Delgado
2022 年 10 月 5 日
Wow... it is simple, but you have a lot of code to write. :)
You need to create some properties in your app to store the images and others to control the index, snapshot flag...
For example:
% Properties
app.imgFlag = false;
app.imgIdx = 1;
app.imgArray = repmat({[]}, 1, 5); % Five images
app.imgTime = 1; % 1 second
% StateButtonCallback
if app.StateButton.Value
app.imgFlag = true;
else
app.imgFlag = false;
end
% Update imgArray
function Fcn_imgSnapshot(app)
app.Camera = webcam;
while app.imgFlag
tic
app.imgArray(app.imgIdx) = snapshot(app.Camera);
if app.imgIdx < numel(app.imgArray)
app.imgIdx = app.imdIdx+1;
else
app.imgIdx = 1;
end
t1 = toc;
if t1 < app.imgTime
pause(app.imgTime-t1)
end
end
end
Or maybe create a timer, so you can avoid the loop.
% Properties
app.imgIdx = 1;
app.imgArray = repmat({[]}, 1, 5);
% Startup of your app
app.tmr = timer('Period', 4, 'ExecutionMode', 'fixedRate', 'TimerFcn', @app.Fcn_imgSnapshot)
% TimerButtonCallback (StateButton)
if app.TimeButton.Value
start(app.tmr)
else
stop(app.tmr);
end
% Update imgArray
function Fcn_imgSnapshot(app)
app.imgArray(app.imgIdx) = snapshot(app.Camera);
if app.imgIdx < numel(app.imgArray)
app.imgIdx = app.imdIdx+1;
else
app.imgIdx = 1;
end
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で MATLAB Support Package for IP Cameras についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!