Need help to capture and save image at every 5 seconds from both camera?
17 次查看(过去 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 中查找有关 GigE Vision Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!