I have this code for image subtraction and trake moving object its work well but i want to draw bounding rectangle box arround object detected how i can do this insted of using centroied

1 vue (au cours des 30 derniers jours)
%function[x,y,ibw]=isub(i_aft,i_bef)
%Takes two images from two frames ,subtracts them and detect the position
%of object by threshholding and calculating centroid
function[x,y,ibw]=isub(i_aft,i_bef)
%subtract image
i_sub=i_bef-i_aft;
%convert to binary
igray=rgb2gray(i_sub);
level=graythresh(i_sub);
ibw=im2bw(i_sub,level);
%compute centre of gravity
ibw = imfill(ibw,'holes');
L=bwlabel(ibw);
stats=regionprops(L,'Area','Centroid');
ar=[stats.Area];
s=[stats.Centroid];
armax=max(ar);
mx=max(max(L));
for i=1:mx
if stats(i).Area==armax
centroid=stats(i).Centroid;
end
end
x=centroid(1);
y=centroid(2);
x=round(x);
y=round(y);
[m n r]=size(i_aft);
for k=1:m
for l= 1:n
if (k==y && l==x)
for t= 0:4
i_aft(k-t,l-t,:)= 0;
i_aft(k-t,l-t,3)=255;
i_aft(k-t,l+t,:)= 0;
i_aft(k-t,l+t,3)=255;
end
end
end
end
imshow(i_aft);

Réponses (2)

Image Analyst
Image Analyst le 26 Sep 2013
Just ask for the bounding box:
stats=regionprops(L,'Area','Centroid', 'BoundingBox');
Did you not know that it was available from regionprops()? Take a look at the help - it offers a lot of other measurements you can ask for besides those.
  2 commentaires
amarnath
amarnath le 13 Mar 2014
Modifié(e) : amarnath le 13 Mar 2014
all I need to have is to get a bounding box and avoid tracking of other moving objects other than the first fixed object.......and also how can we interface stepper motors for this code to obtain a pan-tilt operation mechanism . . . . .can you please helpme for this mr.Analyst
giving bounding box in the command did no help sir. . ..
Image Analyst
Image Analyst le 13 Mar 2014
The Computer Vision System Toolbox has tracking capability and lots of demos. Don't rewrite it, just buy it and use it.

Connectez-vous pour commenter.


amarnath
amarnath le 13 Mar 2014
all I need to have is to get a bounding box and avoid tracking of other moving objects other than the first fixed object.......and also how can we interface stepper motors for this code to obtain a pan-tilt operation mechanism . . . . .can you please helpme for this mr.Analyst or anyone

Community Treasure Hunt

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

Start Hunting!

Translated by