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);

回答(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