31-01-2013, 03:46 PM
Dear sir/madam,
I'm Aarthi, studying Final year Computer science Engineering in Coimbatore. I need to know how to count the vehicles in a video. The vehicles are of not the same speed. Till now ,I have tried to convert the videos into frames,and those frames to gray scale. Gray scale images are again converted into binary images for counting. The following is the code of my work,
clc
clear all
n=0;
% Read movie
SF = 1; %Starting Frame
MV = mmreader('a.avi'); %To read Movie
EF = MV.NumberofFrames ; %Ending Frame
img = read(MV,1); %reading particular frame
A = double(rgb2gray(img)); %motion vector works on Gray Image formate
[height width] = size(A); %Movie size?
% motion estimation
h1 = figure(1);
for f = SF: EF %Frame from SF To EF
B = A;
img = read(MV,f);
A = double(rgb2gray(img));
%Foreground Detection
thresh=11;
fr_diff = abs(A-B);
for j = 1:width
for k = 1:height
if (fr_diff(k,j)>thresh)
fg(k,j) = A(k,j);
else
fg(k,j) = 0;
end
end
end
subplot(2,2,1) , imagesc(img), title (['Orignal Sequence Frame#',int2str(f)]);
subplot(2,2,2) , imshow(mat2gray(A)), title ('Previous Frame');
subplot(2,2,3) , imshow(mat2gray(B)), title ('Next Frame');
sd=imadjust(fg);
level=graythresh(sd);
m=imnoise(sd,'gaussian',0,0.025);
k=wiener2(m,[5,5]);
bw=im2bw(k,level);
[labeled,numObjects] = bwlabel(bw,4);
n=n+numObjects;
subplot(2,2,4) , imagesc(bw), title (['Foreground #',n]);
hold off;
pause (.1);
% saveas(h1,strcat('Result-Paris-',num2str(f)),'jpg');
end
disp(n);
Kindly help me in completing my work.