Need help to capture and save image at every 5 seconds from both camera?
조회 수: 9 (최근 30일)
이전 댓글 표시
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);
댓글 수: 0
답변 (1개)
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
참고 항목
카테고리
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!