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);
댓글 수: 0
답변 (2개)
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
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. . ..
Image Analyst
2014년 3월 13일
The Computer Vision System Toolbox has tracking capability and lots of demos. Don't rewrite it, just buy it and use it.
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!