How to capture frame (image) using webcam at specific time interval (e.g. at 100ms or 10 frames per second) in matlab app designer?
조회 수: 4 (최근 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!