MATLAB Answers

Capture from Multiple Webcams

31 views (last 30 days)
Greg on 21 Apr 2011
Commented: Walter Roberson on 23 Aug 2019
Hi everyone, I am trying to use the Image Acquisition Toolbox to capture images from six webcams at the same time. The problem I am having is that only five actually work in MATLAB, even though all six will preview at the same time in other webcam programs. Is there a way to get MATLAB to use MJPEG instead of YUY2? The cameras do support MJPEG, which uses considerably less bandwidth, but it does not show up in matlab.
I am on windows 7 x64, with 12 gb of RAM. The CPU usage is below 30% with all cameras previewing. Are there any limitation I don't know about that would cause only 5 to work at a time? Maybe matlab is limiting memory or cpu usage, even though I have plenty? Any suggestions?
Sriram Kollipara
Sriram Kollipara on 17 Jul 2017
Can you possibly send me the code you are using to do this. If you cannot can you suggest some way or point me some resources that can help. It would be a great help.
Thanks Greg.

Sign in to comment.

Answers (7)

David Tarkowski
David Tarkowski on 22 Apr 2011
The most likely issue is that you are running into bandwidth limitations somewhere on your PC. My first thought was that it was a USB bandwidth limitation, but if you are able to acquire from five cameras simultaneously, I would guess that you are using at least two or three USB root controllers. This would mean that the culprit is likely not the USB bus, but the bridge between the USB controllers and the rest of the PC. If that is the case, there isn't too much that you can do. If you use an PCIe expansion card like this one (just the first example that I found) that might work, but that is really just a hunch.
We don't generally support JPEG compression from cameras since JPEG is a lossy compression method. This means that data is lost and the returned images are not true representations of the data that was captured by the camera. I can look into adding that in for a future version of the toolbox, but I'll have to think about it.
Mohsin on 30 May 2011
Hey im facing the same problem. Using a PCI usb card, I was able to acquire video from 4 cameras on my desktop but on my laptop, I cant seem to get video from more than 2 cameras. I tried a usb hub as well but it wont let me get video from more than 2 cameras though it shows all the four cameras on the image acquisition tool box. can u help? and can u please tell me about the usb root controller thing?
I am working on a core i3 with 3gb ram and 64bit windows 7 ultimate.

Sign in to comment.

Tunc Askan
Tunc Askan on 3 Sep 2014
Here is my case, may be it helps the community ;).
  • 16 Logitech HD 920 Webcams running at 15 fps, Full HD, RGB > ~90 MBs data flow per webcam
  • Motherboard with Intel X79 Chipset, 64 GB RAM
  • Windows 7 64 Bit
  • Matlab R2013b & R2014a
Matlab image engine is not able to transfer the acquired video data (nearly 1.4 GBs for my case) directly to HDD during the capture, even if you use SSDs with enough bandwidth (source: Matlab Support). So, if you want to capture frame synchronized videos you need let whole data flow to RAM during the capture. Here is important to check the specs of your motherboard, chipset, USB host controllers etc. in order to avoid a bottleneck (check chipset diagrams). I'm using in my case 3 extra USB host controllers (<>) and two host controllers on the motherboard (bandwidth limited!). And the most important thing is to use the Microsoft USB Webcam driver, not the driver of the webcam! My experience is, you are not able to control the frame rate and capture synchronized through imaq when you don' t use Microsoft drivers. Below you can find an image, which shows the trigger times for 16 webcams.
  1 Comment
rohan gupta
rohan gupta on 21 Jan 2015
I am trying to record videos using two logitech c170 webcam at 15fps each. But I am unable to do so. Can you help me with this.
Windows 7 64 Bit
Matlab R2014a
I am using laptop which has 4GB RAM

Sign in to comment.

Mark Jones
Mark Jones on 28 Apr 2011
When all 6 are plugged in, do all 6 at least show up using IMAQHWINFO?
Is it always the same camera that is not accessible and if so, is this camera accessible from MATLAB when it is the only camera plugged in?
Chinmayee on 28 Apr 2014
I am working on stereovision. I want to acquire images simultaneously from 2 Logitech webcams connected via USB ports. But I am getting the images with a long delay. How can I reduce the delay between the two captures or make the 2 cams trigger simultaneously?

Sign in to comment.

Chamil Ranathunga
Chamil Ranathunga on 30 Aug 2015
Remove your logitec webcam softwares .Only keep the drivers .then it will work

jorge alejandro guerrero díaz
Edited: Walter Roberson on 14 Jun 2017
do you guys know how can i record video from matlab? i mean i doing it right now but when i use 1280xsomthing it record the video but when i play it, the video runs too fast, i wrote 30 frames per second but it does not work anyways, so can you help me? it works well with less than 900x something!
function control_Callback(~, ~, handles)
% hObject handle to control (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global VidObj cam vid aviobj
if cam == 0
% nom = datestr(now, 'local');
% nombre = strcat(nom, '.avi');% Prepare the new file.
vid = VidObj;
aviobj = VideoWriter(fullfile(ca,na));
vid.LoggingMode = 'disk';
vid.DiskLogger = aviobj;
vid.TriggerRepeat = inf;
set(handles.control, 'String', 'PARAR');
set(handles.control, 'ForegroundColor','black');
set(handles.configuracion, 'enable', 'off');
set(handles.v_previa, 'enable', 'off');
cam = 1;
% aviobj =
clear vid;
clear aviobj;
set(handles.control, 'String', 'GRABAR');
set(handles.control,'ForegroundColor', 'red');
set(handles.configuracion, 'enable','on');
set(handles.v_previa, 'enable', 'on');
cam = 0;
jorge alejandro guerrero díaz
thank you i did it, i think it works nice, hope you have a nice day!!!.

Sign in to comment.

Eduardo Aguilar
Eduardo Aguilar on 22 Feb 2018
Hi Greg. Actually I wanna connect five microscope to Matlab R2016 but it send me an error when the third microscope start. Could you tell me how you connect your cams please?

Piotr Bartczak
Piotr Bartczak on 22 Aug 2019
Edited: Piotr Bartczak on 22 Aug 2019
Hi All,
I was following your topic and got quite nice answers already. Perhaps my case is slighlty different since I am trying to run stereocamera via Matlab toolbox. I believe that the whole problem is related to the USB "hub" that allows video stream of two cameras via one USB 2.0 cable.
Camera type:
Fisheye 180degree Non-Fixed Stereo Webcam OmniVision OV9712 HD 720P Dual Lens USB Camera Module with Two Cameras Boards
Both cameras can be esaily detected but there is no stream/privew available. I am able to change all camera properties however, after trying to prview it there is no error in the command line and no image in the window.
{'USB2.0 Camera' }
{'Integrated Camera'}
{'USB2.0 Camera' }
SelectedCam="USB2.0 Camera";
cam1 = webcam(SellistCamPC(1))
cam2 = webcam(listCamPC(3))
cam1.Exposure = -5;
cam1.ExposureMode = 'manual';
cam1.WhiteBalanceMode = 'manual';
cam1.Saturation = 0;
Can it be related to the same name of both cameras ("USB2.0 Camera") ?
>> cam1.Name="Camera1";
You cannot set the read-only property 'Name' of webcam.
Unfortunately, there is no way of changing it ?
Could you help me with it ?
Ps. both cameras do work properly when using basic webcam viewer, e.g., AMCap
Walter Roberson
Walter Roberson on 23 Aug 2019
webcamlist() can return a list of the webcams . webcam() can accept a device number.
However: if your webcams are identical in name, then you will have difficulty in imposing a unique ordering on them. If you unplug one of the webcams and plug it back in, it is not necessarily going to reappear at the same place in the list.
The device appears to be primarily 1280X720 MJPEG 30fps YUY2 9fps (or higher frame rates for lower sizes.) Simulink might be able to handle it; . Other than that, the only MJPEG support that I seem to find appears to be for ipcam . Even if you were able to get a single JPEG frame from the camera, I would worry about the YUYV2 format. I would suggest trying to snapshot() a frame and examine it.
Sites I am looking at estimate that MJPEG 720P is about 10 megabits per second per camera at 10 fps. In theory even 4 of those should not strain USB 2.0

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!