Moving Object Detection in Matlab

i hav run this code in Matlab 2013a, and detected the moving object, the problem is, i am not able to obtained the background sequence without object.......
%Moving Object Detection in Matlab
clc clear all
% Read movie
SF = 1; %Starting Frame EF = 200; %Ending Frame MV = mmreader('video.avi'); %To read Movie
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=65;
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');
subplot(2,2,4) , imagesc(fg), title ('Foreground');
hold off;
pause (.5);
end

답변 (1개)

Dima Lisin
Dima Lisin 2014년 10월 24일

2 개 추천

If you have the Computer Vision System Toolbox, try using vision.ForegroundDetector.

댓글 수: 3

Mohd Nayeem
Mohd Nayeem 2014년 10월 29일
First of all thanks u very much for the acknowledgement.....
yes i tried with vision.ForegroundDetector with CV toolbox but the obtained output was just the object detection in a sequence....
i have successfully detected moving object (foreground) in a video sequence, but the problem i am still facing is to obtain only the background image.....
hope u understand my question, and thanks in advance....
Dima Lisin
Dima Lisin 2014년 10월 31일
Oh, I see. The simplest thing to do would be to take some number of video frames, and compute the median value for each pixel. That may give you a reasonably good image of the background, depending on how much motion there is in the scene.
If you have the foreground masks produced by vision.ForegroundDetector, then you can exclude the pixels known to be foreground from your computation. In this case you may even be able to use the mean instead of median.
Could you share the code for " to take some number of video frames, and compute the median value for each pixel.". I tried but its giving error while running. I need to find the bakground in a similar way. Thanks.

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

카테고리

도움말 센터File Exchange에서 Tracking and Motion Estimation에 대해 자세히 알아보기

질문:

2014년 10월 21일

댓글:

2015년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by