function d = Detection(video)
if ischar(video)
    % Load the video from an avi file.
    avi = aviread(video);
    pixels = double(cat(4,avi(1:1:end).cdata))/255;
    clear avi
else
    % Compile the pixel data into a single array
    pixels = double(cat(4,video{1:2:end}))/255;
    clear video
end

% Convert to RGB to GRAY SCALE image.
nFrames = size(pixels,4);
disp(nFrames);
for f = 1:nFrames
       pixel(:,:,f) = (rgb2gray(pixels(:,:,:,f)));
end
rows=240;
cols=320;
nrames=f;
for l = 2:nrames
    d(:,:,l)=(abs(pixel(:,:,l)-pixel(:,:,l-1)));

    k=d(:,:,l);
     bw(:,:,l) = im2bw(k, .2);
    %bw1=bwlabel(bw(:,:,l));
    imshow(bw(:,:,l))
    % disp(bw);
    hold on

    drawnow,pause(0.1);

    hold off

end;




