MATLAB Answers

Hashem Burki

taking input from two cameras at a same time in Matlab

Asked by Hashem Burki
on 9 May 2011

how can i use and take input from two cameras at the same time?

  0 Comments

2 Answers

Answer by David Tarkowski
on 11 May 2011
 Accepted answer

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 Comments

Tiago
on 15 Feb 2013

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?

Image Analyst
on 15 Feb 2013

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);
Tiago
on 15 Feb 2013

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?


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today