Trouble plotting Bounding Boxes on a Black and White Foreground Video.

1 visualización (últimos 30 días)
Hello All,
I have implemented Mixture of Gaussians algorithm to separate background and foreground in a video of 100 frames (30 fps) and then subtracted the background frame from the image to get a foreground frame.Then I saved all the 100 foreground frames into a .avi file.
Now since I have removed the entire background I now wanted to calculate velocity of the moving object by calculating Centroid of the connected components in successive frames and then finding out the distance between the two centroids in the successive frames and then by using fps I will find the velocity and apart from this I also want to see the Bounding Boxes on those connected components which can clearly show the moving objects in the video.Tried a small code though I didn't get any error during plotting I cannot see anything which I have desired.Quite sure that there should be something more done at the end while plotting.
clear all
close all
clc
tic
disp('Execution Started')
vidobj = VideoReader('mixture_of_gaussians_output1.avi');
NumFrames = vidobj.NumberOfFrames;
frames = cell(1,NumFrames);
bwframe = cell(1,NumFrames);
cc = cell(1,NumFrames);
for m=1:NumFrames
frames{m} = rgb2gray(read(vidobj,m));
end
[r c] = size(frames{20});
for m = 1:NumFrames
level = max(frames{m}(:));
for n = 1:r
for o = 1:c
if frames{m}(n,o)> level-10 && frames{m}(n,o) <= level+10
frames{m}(n,o) = 255;
else
frames{m}(n,o) = 0;
end
end
end
bwframe{m} = frames{m};
end
figure,
for m=1:NumFrames
% arop{m} = bwareaopen(bwframe{m},30);
% bw{m} = bwlabel(arop{m},8);
bw{m} = bwconncomp(bwframe{m},8);
stats{m} = regionprops(bw{m},'BoundingBox','Centroid');
imshow(bwframe{m})
hold on
for object = 1:length(stats{m})
bb = stats{m}(object).BoundingBox;
bc = stats{m}(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2),'-m+')
a = text(bc(1)+15,bc(2),strcat('X: ',num2str(round(bc(1))),' Y: ',num2str(round(bc(2)))));
set(a,'FontName','Arial','FontWeight','bold','FontSize',12,'Color','yellow');
end
end
hold off
Kindly help me out with this one.

Respuesta aceptada

Image Analyst
Image Analyst el 25 de Jul. de 2011
See my code to your duplicate posting in the newsgroup: http://www.mathworks.com/matlabcentral/newsreader/view_thread/310846

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by