MATLAB Answers

Greg
1

Capture from Multiple Webcams

Asked by Greg
on 21 Apr 2011
Latest activity Commented on by 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?
Thanks

  4 Comments

Show 1 older comment
Mohsin
on 27 May 2011
Hey greg im facing the same problem as Mr.Chakraborty. 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?
Thanx
Hello, I am not able to connect more than 1 camera to the image acquisition blocks from simulink. It is not even getting recognized. can you please suggest what I should be doing. I am using a Windows 7 PC with 16 GB RAM and 2013 a matlab version
Hi,
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. Email:sriramgs14@gmail.com
Thanks Greg.

Sign in to comment.

7 Answers

Answer by 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.

  3 Comments

Greg
on 22 Apr 2011
Thanks David,
I do have 2 USB root controllers. The problem is, in TinCam, which is just a simple webcam viewer that supports multiple webcams, I can view all six cameras simultaneously. While in Matlab, 5 cameras will stream fine, and when I preview the sixth, it will show just the first frame and nothing else. Same resolution/FPS/everything. Why?
I understand JPEG is lossy, but I think its best to give the customer the option!
Thanks again
Greg,
The issue is almost certainly the lack of JPEG compression in the toolbox. TinCam is probably using the JPEG compression which uses significantly less bandwidth.
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.
thanx

Sign in to comment.


Answer by 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 (<http://www.delock.de/produkte/G_89325/merkmale.html>) 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

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.


Answer by 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?

  3 Comments

Greg
on 2 May 2011
Yes, they do:
AdaptorDllName: 'C:\Program Files\MATLAB\R2010b\toolbox\imaq\imaqadaptors\win64\mwwinvideoimaq.dll'
AdaptorDllVersion: '4.0 (R2010b)'
AdaptorName: 'winvideo'
DeviceIDs: {[1] [2] [3] [4] [5] [6] [7]}
DeviceInfo: [1x7 struct]
(The 7th is a Novel-H9D camera that is not plugged in)
It is always the 6th camera that I start that does not work. If I then stop all of the others, it will work by itself. It definitely seems like a bandwidth issue, but it is curious that 6 work in TinCam, but 5 in Matlab.
ANKUR
on 9 Jan 2013
i am also facing the same problem, but i am able to run 3 webcam only.Please guide me to take image from 6 webcam for image processing. I am running Matlab R2011b version on 64bit 4gb ram window 7 pc.
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.


Answer by Chamil Ranathunga on 30 Aug 2015

Remove your logitec webcam softwares .Only keep the drivers .then it will work

  0 Comments

Sign in to comment.


Edited by 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
[na,ca]=uiputfile({'*.avi'});
% 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;
start(vid);
set(handles.control, 'String', 'PARAR');
set(handles.control, 'ForegroundColor','black');
set(handles.configuracion, 'enable', 'off');
set(handles.v_previa, 'enable', 'off');
cam = 1;
else
stop(vid);
% aviobj =
close(vid.DiskLogger);
delete(vid);
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;
end

  8 Comments

well i have this and goes good i think do you think i should change something?
if cam == 0
[na,ca]=uiputfile({'*.avi'});
% 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;
start(vid);
set(handles.control, 'String', 'PARAR');
set(handles.control, 'ForegroundColor','black');
set(handles.configuracion, 'enable', 'off');
set(handles.v_previa, 'enable', 'off');
cam = 1;
else
stop(vid);
% aviobj =
close(vid.DiskLogger);
delete(vid);
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;
end
if cam == 0
[na,ca]=uiputfile({'*.avi'});
% 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;
vid.FrameRate = 3.75; %NEW LINE
start(vid);
set(handles.control, 'String', 'PARAR');
set(handles.control, 'ForegroundColor','black');
set(handles.configuracion, 'enable', 'off');
set(handles.v_previa, 'enable', 'off');
cam = 1;
else
stop(vid);
% aviobj =
close(vid.DiskLogger);
delete(vid);
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;
end
thank you i did it, i think it works nice, hope you have a nice day!!!.

Sign in to comment.


Answer by 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?

  0 Comments

Sign in to comment.


Answer by Piotr Bartczak on 22 Aug 2019
Edited by 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.
listCamPC=webcamlist
{'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;
preview(cam1);
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

  3 Comments

Usb hubs can be a problem. A USB switch would be better than a hub, but better yet would be two separate cables... preferably connected to different controllers.
Thanks Walter !
Are there any USB switch avaiable on the market ?
It would be just great to connect 2-4 web cameras via switch/adapter connected to the laptop's USB port and capture image from each camera.
At this stage images do not need to be synchronized but the main idea is to reduce number of occupied USB ports.
When using different software cameras are called via their index and video streamig is possible. Any similar way to avoid calling webcamera via its name ?
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; https://www.mathworks.com/help/xpc/io_ref/fromusbvideodevice.html . 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.