Main Menu

Menu

Sunday 15 May 2011

Read WebCam in Matlab

The following code inputs the WebCam stream to Matlab in a new figure:

video = videoinput('winvideo')
set(video,'TriggerRepeat',Inf);
video.FrameGrabInterval = 5;
vid_src = getselectedsource(video);
set(vid_src,'Tag','motion detection setup');
figure;
start(video)
while(video.FramesAcquired<=inf)
data = getdata(video,2);
diff_im = imadd(data(:,:,:,1),-data(:,:,:,2));
imshow(diff_im);
end
stop(video)

Search each command in Matlab for more details (help command)!



or just

video1 = videoinput('winvideo');
preview(video1);

to preview the input:





No comments:

Post a Comment