MATLAB: How to make a live video from webcam to appear on the fig file which i have created

webcam

how to make a live video from webcam to appear on the fig file which i have created

Best Answer

You may try these.
clear all;
imaqmem(80000000) ;
aviobj = avifile('myavifile6');
aviobj.quality = 100;
vid = videoinput('winvideo',1,'YUY2_640x480');
set(vid,'returnedcolorspace','rgb');
set(vid,'framespertrigger',inf);
set(vid,'timerperiod',1);
set(vid,'timeout',500);
set(vid, 'DiskLogger',aviobj);
set(vid,'loggingmode','disk');
vidRes = get(vid, 'VideoResolution');
nBands = get(vid, 'NumberOfBands');
subplot(1,2,1);hImage = imshow( zeros(vidRes(2), vidRes(1), nBands),'InitialMagnification',100' );
preview(vid,hImage);
start(vid)
while(1)
frame = getsnapshot(vid);
subplot(1,2,2);imshow(frame,'InitialMagnification',100');
Ha_ax=gca;
str = get(gcf,'currentkey');
if strcmp(str,'space')
break;
else
continue;
end
end
stop(vid);
aviobj =close(aviobj );
Related Question