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 次查看(过去 30 天)
%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);

回答(2 个)

Image Analyst
Image Analyst 2013-9-26
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 个评论
amarnath
amarnath 2014-3-13
编辑:amarnath 2014-3-13
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. . ..

请先登录,再进行评论。


amarnath
amarnath 2014-3-13
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

类别

Help CenterFile Exchange 中查找有关 Switches and Breakers 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by