본문 바로가기
Programming/Matlab, Octave, Scilab

[Matlab] Webcam 을 이용해서 동영상 보기 코드

by 도파공 2010. 5. 1.
728x90
반응형

인터넷을 검색하다 보니 예제가 있어서 스크랩 했다. 스크랩하고서 그 사이트 정보를 기록했어야 했는데.. 다른 것 하다보니.. 삭제되어 버렸서 다시 확인되는 데로 업데이트 하도록 하겠다.

아래의 소스는 웹캠으로부터 동영상을 받아서 Matlab상에서 디스플레이 해주는 코드이다.

 

% Create video input object.
vid = videoinput('winvideo')
% Set video input object properties for this application.
% Note that example uses both SET method and dot notation method.
set(vid,'TriggerRepeat',Inf);
vid.FrameGrabInterval = 5;
% Set value of a video source object property.
vid_src = getselectedsource(vid);
set(vid_src,'Tag','motion detection setup');
% Create a figure window.
figure;
% Start acquiring frames.
start(vid)
% Calculate difference image and display it.
while(vid.FramesAcquired<=500) % Stop after 100 frames
data = getdata(vid,2);
diff_im = imadd(data(:,:,:,1),-data(:,:,:,2));
imshow(diff_im);
end
stop(vid)

 

728x90
반응형

댓글