how to detect the objects from a video?

조회 수: 1 (최근 30일)
aarthi ramasamy
aarthi ramasamy 2013년 1월 24일
I have tried to convert the video into frames. And then to a binary images where the object is identified as a white patch,but I couldn't count the the objects. Moreover our project is based on the vehicle counting system using a ip camera. I dont have computer vision toolbox in matlab. Kindly,reply me back. This is the code,I have done so far,
**clc
clear all
% 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);
subplot(2,2,4) , imagesc(bw), title ('Foreground');
hold off;
pause (.1);
% saveas(h1,strcat('Result-Paris-',num2str(f)),'jpg');
end**

채택된 답변

jasche
jasche 2013년 1월 24일
can you post a clearly intended code. Have you decided on an algorithm to binarize you input frames ?
One way to count targets can be to identify the maximum intensity point in the frame and find the connected region.
  댓글 수: 2
Image Analyst
Image Analyst 2013년 1월 24일
He used graythresh() which is a binarization routine.
aarthi ramasamy
aarthi ramasamy 2013년 2월 2일
Since I'm new to matlab, I don't know how to implement the algorithms. My objective here is to count the objects that move in a video. Below code,converts the video into frames and then to grayscale . The grayscale frames are again converted into binary From where I can count the objects. But it leads to a wrong count. I'm failing in that part. I need your idea in solving the problem.
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) = 0;
else
fg(k,j) = A(k,j);
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);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tracking and Motion Estimation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by