Matlab读取摄像头

% cam_info = imaqhwinfo('winvideo');
% cam_info.DeviceInfo.DeviceID
% cam_info.DeviceInfo.SupportedFormats

close all;
if(exist('vid','var'))
    stop(vid);
    delete(vid);
end

%imaqhwinfo

vid = videoinput('winvideo', 1, 'YUY2_1280x720');
set(vid, 'ReturnedColorSpace', 'RGB');
% preview(vid);

src = getselectedsource(vid);
frameRates = set(src, 'FrameRate');
src.FrameRate = frameRates{1};
actualRate = str2num( frameRates{1} )

avi = avifile('timelapsevideo','fps',actualRate);

triggerconfig(vid, 'manual');
start(vid);

for i=1:100
    img=getsnapshot(vid);
%     imshow(img);
%     pause(0.01);
    F = im2frame(img);      % Convert I to a movie frame
    avi = addframe(avi,F);  % Add the frame to the AVI file
end;

stop(vid)
delete(vid);

avi = close(avi);      

Aucun commentaire:

Enregistrer un commentaire