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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
khalid imtiaz imtiaz ali
el 26 de Sept. de 2013
Comentada: Image Analyst
el 13 de Mzo. de 2014
%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 comentarios
Respuestas (2)
Image Analyst
el 26 de Sept. de 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 comentarios
amarnath
el 13 de Mzo. de 2014
Editada: amarnath
el 13 de Mzo. de 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
el 13 de Mzo. de 2014
The Computer Vision System Toolbox has tracking capability and lots of demos. Don't rewrite it, just buy it and use it.
amarnath
el 13 de Mzo. de 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
0 comentarios
Ver también
Categorías
Más información sobre Switches and Breakers en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!