taking input from two cameras at a same time in Matlab

 채택된 답변

David Tarkowski
David Tarkowski 2011년 5월 11일
In general working with two cameras is the same as working with a single camera. You create a videoinput object for each device that you wish to capture from and the call start on each device:
vid1 = videoinput('winvideo', 1);
vid2 = videoinput('winvideo', 2);
start([vid1 vid2]);
These devices will be started at roughly the same time, but will not by synchronized due to delays imposed by the operating system and drivers in actually starting them. To synchronize multiple devices precisely, you generally need to use devices that support hardware triggering.

댓글 수: 5

I have the same problem.
I'm able to preview each webcam separately but when I try to preview both I get this error:
Error using imaqdevice/preview (line 177)
The image acquisition device failed to start acquiring images.
This is my code (it only previews vid1):
vid1 = videoinput('linuxvideo',1);
vid2 = videoinput('linuxvideo',2);
subplot(211)
h1 = image;
preview(vid1,h1)
subplot(212)
h2 = image;
preview(vid2,h2)
What's with the "h=image" line? image() is a function that takes an array as an argument, and you didn't supply anything.
my bad, but even something as simple as:
vid1 = videoinput('linuxvideo',1);
vid2 = videoinput('linuxvideo',2);
preview(vid1)
preview(vid2)
will give the same error.
Any advice on previewing two cameras?
You need to give it a handle to an image object:
axes(handles.axes1);
handleToImageInAxes1 = image(zeros(800,600));
% Turn on the live video.
preview(vidobj, handleToImageInAxes1);
axes(handles.axes2);
handleToImageInAxes2 = image(zeros(800,600));
% Turn on the live video.
preview(vidobj, handleToImageInAxes2);
I did like this:
vid1 = videoinput('linuxvideo',1);
vid2 = videoinput('linuxvideo',2);
handles.axes1 = subplot(1,2,1);
axes(handles.axes1);
handleToImageInAxes1 = image(zeros(800,600));
preview(vid1, handleToImageInAxes1);
handles.axes2 = subplot(1,2,2);
axes(handles.axes2);
handleToImageInAxes2 = image(zeros(800,600));
preview(vid2, handleToImageInAxes2);
and still the same error at the second preview. Any idea?

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Hassan Mehmood Khan
Hassan Mehmood Khan 2017년 9월 17일
i did this to get snapshot from two cams at same time:
% webcamlist identification
clc;
clearvars;
webcamlist
cam=webcam;
cam2=webcam(2);
cam.AvailableResolutions;
cam2.AvailableResolutions;
cam.Resolution='640x480';
cam2.Resolution='640x480';
% preview(cam);
% preview(cam2);
img=snapshot(cam);
img2=snapshot(cam2);
img3=snapshot(cam);
img4=snapshot(cam2);
figure;
subplot(3,3,1);
imshow(img3);
subplot(3,3,2);
imshow(img4);
output
ans =
'Webcam C170'
'Logitech HD Webcam C270'

질문:

2011년 5월 9일

댓글:

2020년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by