필터 지우기
필터 지우기

Need help to capture and save image at every 5 seconds from both camera?

조회 수: 9 (최근 30일)
M Faisal Riyad
M Faisal Riyad 2020년 10월 28일
댓글: M Faisal Riyad 2020년 11월 2일
Hello,
I wrote the following code - which can read 2 USB camera connected to my PC. Now i want to create a loop or function that will tell each camera to take a snapshot at every 10 seconds and save them in the disk. How do i do that?
clc; clear;
close all; objects = imaqfind %find video input objects in memory
delete(objects) %delete a video input object from memory
vid1 = videoinput('winvideo', 1, 'MJPG_1280x720');
vid2 = videoinput('winvideo', 3, 'RGB24_1824x1216');
%camera 1 - for force sensor beam
vid1.FramesPerTrigger = 1;
vid1.TriggerRepeat = inf;
triggerconfig(vid1, 'manual');
vid1.TimerFcn = 'trigger(vid1)';
vid1.TimerPeriod = 5;
%camera 2 - strain measurement
vid2.FramesPerTrigger = 1;
vid2.TriggerRepeat = inf;
triggerconfig(vid2, 'manual');
vid2.TimerFcn = 'trigger(vid1)';
vid2.TimerPeriod = 5;
%view the camera
preview(vid1);
preview(vid2);
snapshot1 = getsnapshot(vid1);
snapshot2 = getsnapshot(vid2);

답변 (1개)

Rishik Ramena
Rishik Ramena 2020년 11월 2일
편집: Rishik Ramena 2020년 11월 2일
For continuous capture, you can use the getsnapshot function inside a loop with a pause function. For saving the snapshot to the disk you can use imwrite. Here's a sample snippet.
i = 1;
while true % run for indefinitely long time
snapshot1 = getsnapshot(vid1);
snapshot2 = getsnapshot(vid2);
imwrite(snapshot1, ['camera1_' num2str(i) '.png']); %save the snapshots for camera1
imwrite(snapshot2, ['camera2_' num2str(i) '.png']); %save the snapshots for camera2
pause(10); % pause for 10 seconds
i = i+1;
end
If you're worried about the timing overheads in these do have a look this example.

카테고리

Help CenterFile 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!

Translated by