Code covered by the BSD License  

Highlights from
Motion Detector

Motion Detector

by

 

A video based function which detects when someone/something moves in the frame.

motiondetector(s)
%Copywrite Abhilash Harpale (c) 2009.
%   MOTION DETECTOR VERSION 1.0
%   based on color images
%   This version is sensitive to color changes.
%   's' is the background noise. 

function motiondetector(s)
vid=videoinput('winvideo',1);
triggerconfig(vid,'manual');
set(vid,'FramesPerTrigger',1);
set(vid,'TriggerRepeat', Inf);
set(vid,'ReturnedColorSpace','rgb');
start(vid);
i=0;
j=0;
f=zeros(480,640,3,2);
load splat
disp('motion detector on');

while(1)
    trigger(vid);
    temp=getdata(vid,1);
    imshow(temp);
    f(:,:,:,mod(i,2)+1)=temp;
    g=f(:,:,:,1)~=f(:,:,:,2);
    if(sum(sum(sum(g)))>((s/100)*480*640*3))
         disp('motion detected');
        j=j+1;
    end
    if(mod(j,5)==0)
        clc
        disp('motion detector on');
        y=y(1:3000);
        for a=1:4
            wavplay(y,4500,'sync');
        end
    end
    %disp('difference');
    %disp(sum(sum(sum(g))));
    i=i+1;
end

    

Contact us