Capture video from multiple webcams simultaneously.

14 ビュー (過去 30 日間)
Sriram Kollipara
Sriram Kollipara 2017 年 7 月 17 日
コメント済み: Otto Sponring 2019 年 6 月 18 日
Hi everyone, I am trying to use the MATLAB to record videos from 4 web-cameras simultaneously. I am new to MATLAB and am only find help to record one video at a time and that too only at 4fps when i know the camera can record at 30FPS. I would like some help with how to proceed with this coding. I am using webcam object now to preview the video like in this link
https://www.mathworks.com/help/supportpkg/usbwebcams/ug/acquire-webcam-images-in-a-loop.html
I am using 4 Genius full HD cameras, My PC runs on windows 10 x64, 8gb RAM and 2GB Nvidia GPU. Any help is appreciated. Please de tell me if any further information is required or if there are any toolboxes that can help.
  1 件のコメント
Otto Sponring
Otto Sponring 2019 年 6 月 18 日
Sriram if this is still relevant to you I just wrote a small program and glad to share with you to capture multiple USB camera and live stream.
n=webcamlist;
m=size(n);
sw=m(1);
switch(sw)
case 1
cam1=webcam(1);
cam1.Resolution='640x480';
for i=1:200
if strcmp(s,'space')==1
hold off;
break;
end
img1=snapshot(cam1);
img1 = imresize(img1,0.5);
hold on;
figure(3)=imshow(img1);
hold off;
end
case 2
h=figure;
set(h,'KeyPressFcn',@KeyPressCb);
cam1=webcam(1);
cam2=webcam(2);
cam1.Resolution='640x480';
cam2.Resolution='640x480';
for i=1:200
img1=snapshot(cam1);
img1 = imresize(img1,0.5);
img2=snapshot(cam2);
img2 = imresize(img2,0.5);
hold on;
combImg = imfuse(img1, img2, 'montage');
h=imshow(combImg);
hold off;
end
case 3
cam1=webcam(1);
cam2=webcam(2);
cam3=webcam(3);
cam1.Resolution='640x480';
cam2.Resolution='640x480';
cam3.Resolution='640x480';
for i=1:200
if strcmp(s,'space')==1
hold off;
break;
end
nn=webcamlist;
img1=snapshot(cam1);
img1 = imresize(img1,0.5);
img2=snapshot(cam2);
img2 = imresize(img2,0.5);
img3=snapshot(cam3);
img3 = imresize(img3,0.5);
hold on;
combImg = imfuse(img1, img2, 'montage');
combImg = imfuse(combImg, img3, 'montage');
figure(3)=imshow(combImg);
hold off;
end
end
clear all;
close all;

サインインしてコメントする。

回答 (1 件)

Harsh
Harsh 2017 年 7 月 20 日
If the webcam object for the camera exposes the 'FrameRate' property, then you can try to configure the value to a desired and allowable value. You can learn more about this here.
On the other hand, to get a more granular access to the image acquisition process and hardware, you can use the Image Acquisition Toolbox with the OS Generic Video Interface.
However, note that the frame rate is a characteristic of the camera. Any rate supported by the device and the acquisition system is supported by the toolbox. You can learn more about this here:
To capture video from multiple webcams simultaneously, one possible work flow is to use four independent webcam objects within a parfor loop using functionality from the Parallel Computing Toolbox.
If you need further help with this, please contact MathWorks Technical Support here: https://www.mathworks.com/support/contact_us/.
Please be sure to provide a detailed description of the issue and attach any relevant files / code / examples required to investigate the issue.
  1 件のコメント
Sriram Kollipara
Sriram Kollipara 2017 年 7 月 20 日
Thanks for your input, I've made some progress -
I used videoInput() function with following parameters for 2 cameras
vid1.LoggingMode = 'disk';
vid1.TriggerRepeat = Inf;
vid1.FramesPerTrigger = Inf;
vid1.TimerPeriod = 30;
vid1.TimerFcn = @timelapse_timer;
The problem is I was hoping to record 30 second videos at 30fps. but when the timer runs out after 30 seconds, one camera captures 25 sec video and the other 14 sec video. I wanted the cameras to be in near sync and to record for the same amount of time. I can consider lowering the FPS if I can achieve this.

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by