How do I get images from multiple cameras at the same time?

16 views (last 30 days)
I'm trying to get images from 2 cameras at the same time. But this codes doesn't show and save capture images but only show video previews of two cameras.
Error message is below
----------------------------------------------------
Error using imageDisplayValidateParams>validateCData (line 117) Unsupported dimension.
Error in imageDisplayValidateParams (line 31) common_args.CData = validateCData(common_args.CData,image_type);
Error in imageDisplayParseInputs (line 79) common_args = imageDisplayValidateParams(common_args);
Error in imshow (line 198) [common_args,specific_args] = ...
Error in time_capture_jh2 (line 30) imshow(img1)
----------------------------------------------------
My code is below
----------------------------------------------------
function [ output_args ] = Untitled1( input_args )
%UNTITLED1 Summary of this function goes here
% Detailed explanation goes here
%vid=videoinput('winvideo',2,'yuy2_640x480')
vid1 = videoinput('winvideo', 1, 'yuy2_640x480');
vid2 = videoinput('winvideo', 2, 'yuy2_640x480');
triggerconfig(vid1,'manual');
triggerconfig(vid2,'manual');
set(vid1,'returnedcolorspace','rgb');
set(vid2,'returnedcolorspace','rgb');
set(vid1,'framespertrigger',10);
set(vid2,'framespertrigger',10);
set(vid1,'triggerrepeat',inf);
set(vid2,'triggerrepeat',inf);
start(vid1)
start(vid2)
for ctr = 1:1000
trigger(vid1); trigger(vid2);
preview(vid1); preview(vid2);
img1 = getdata(vid1);
imshow(img1)
fname = ['1003_400' num2str(ctr) '.jpg']; % make a file name
imwrite(img1, fname, 'jpg');
img2 = getdata(vid2);
imshow(img2)
fname = ['1003_200' num2str(ctr) '.jpg']; % make a file name
imwrite(img2, fname, 'jpg');
pause(1800)
%pause(1800);
end
stop(vid1)
stop(vid2)

Answers (1)

dk
dk on 4 Oct 2013
The error message has nothing to to with using 2 cameras. Your FramesPerTrigger setting is 10. so img1 and img2 will be 4-D matrices, where the fourth dimension is the frames. This is also covered here:
Try following in the FOR loop to see what I meant; obviously, this will only save the first of every block of frames you captured with getdata():
imshow(img1(:, :, :, 1));
imwrite(img1(:, :, :, 1), fname, 'jpg');
Also, for speed reasons, you probably don't want to call imshow() in the loop, but call it once outside the loop to pre-generate the image:
himg = imshow(zeros(480, 640, 3)); % returns the handle to the image
then in the FOR loop, just update the image data using the image handle
set(himg, 'Cdata', img1(:, :, :, 1)); % instead of imshow(img1(:, :, :, 1))

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!