I am trying to find "robocup's ball". because it is orange ,so I separated this color and after that test if it is round or not...
Here is an image for which the method does not work, but for others it works:
rgb = imread('E:/robot12.jpg');
imshow(rgb);
hsv=rgb2hsv(rgb);
h=hsv(: , : ,1);
s=hsv(: , : ,2);
v=hsv( : , : ,3);
bw= (h>0.05 & h<0.12) & (s>0.6) & (v> 0.51);
imagesc(bw)
colormap(gray)
se = strel('disk',2);
bw = imclose(bw,se);
bw = imfill(bw,'holes');
imshow(bw)
ball1 = bwareaopen(bw, 50);
imagesc(ball1);
lab = bwlabel(ball1);
s = regionprops(lab, 'Area', 'Perimeter');
sArea = [s.Area];
sPerim= [s.Perimeter];
metric= sPerim.^2/(4*pi.* sArea);
idx = find(metric > 0.7);
gr_fin = ismember(lab, idx);
imshow(gr_fin)
stat = regionprops(gr_fin,'centroid');
imshow(rgb); hold on;
for x = 1: numel(stat)
plot(stat(x).Centroid(1),stat(x).Centroid(2), 'wp','MarkerSize',20,'MarkerFaceColor','b');
end
I don't know how to fix it...
can any one help me with this?