how to run two usb webcams in matlab simutaneoulsy

11 views (last 30 days)
I have to connect two usb webcams simultaneously in Matlab and im using Windows 7 with 4gb RAM. The problem is it shows feed just from one camera and not the other one where as i want both the cameras to run simultaneously. Please help me how to do it.
P.S i do write imaqreset in command window after running the code everytime so its not a problem. Here is my Matlab code % Create video input object. %vid = videoinput('winvideo',1,'RGB24_320x240')
vid1 = videoinput('winvideo',1,'YUY2_320x240')
vid2 = videoinput('winvideo',2,'YUY2_320x240')
% Set video input object properties for this application.
set(vid1,'TriggerRepeat',Inf);
set(vid2,'TriggerRepeat',Inf);
vid1.FrameGrabInterval = 1;
vid2.FrameGrabInterval = 1;
set(vid1,'ReturnedColorSpace','rgb');
set(vid2,'ReturnedColorSpace','rgb');
set(vid1,'FramesPerTrigger', 1000);
set(vid2,'FramesPerTrigger', 1000);
temp1=zeros(240,320,3);
temp2=zeros(240,320,3);
% Create a figure window.
h1=imshow(uint8(temp1));
h2=imshow(uint8(temp2));
pause(0.01)
hold on;
'---------'
% Start acquiring frames.
start(vid1)
start(vid2)
while(vid1.FramesAcquired<=100 && vid2.FramesAcquired<=100) % Stop after 100 frames
tic
data1 = getdata(vid1,1);
data2 = getdata(vid2,1);
set(h1,'Cdata',data1);
set(h2,'Cdata',data2);
flushdata(vid1);
flushdata(vid2);
toc
end
stop(vid1)
stop(vid2)
delete(vid1)
delete(vid2)
% %clear
% close(gcf)

Accepted Answer

sadaf Shahid
sadaf Shahid on 16 Jun 2011
The problem is being solved :) Just write figure after h1=imshow(uint8(temp1));
Both cameras feed will be shown :D

More Answers (0)

Community Treasure Hunt

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

Start Hunting!