how to find robocup`s ball?
조회 수: 2 (최근 30일)
이전 댓글 표시
hi guys, this is my first project in matlab can anyone help me with this? 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...
rgb = imread('E:/robot4.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);
[B,L] = bwboundaries(ball1,'noholes');
stats = regionprops(L,'Area','perimeter');
for k = 1:length(B)
area = stats(k).Area;
s=stats(k).Perimeter;
end
metric=s^2/(4*pi*area);
if (metric>0.8)
stat = regionprops(ball1,'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
end
this shows every orange things and also ball !!! I guess it has problem in calculating perimeter, but I dont know how can I solve it
댓글 수: 0
채택된 답변
Jeff E
2014년 1월 8일
You're going about calculating perimeter in a roundabout fashion. Matlab can convert a specific part of a structure, in your case all the perimeter values from regionprops, to an array. As an added bonus, their order in the array corresponds to the labeled matrix image created by bwlabel/regionprops. You'll want to use bwlabel instead of bwboundaries. The below shows how to perform a simple property check on all the objects in an image, and keep on only those that pass using ismember.
lab = bwlabel(ball1);
s = regionprops(lab, 'Area', 'Perimeter');
sArea = [s.Area];
sPerim= [s.Perimeter];
idx = find((sArea ./ sPerim) < 8);
gr_fin = ismember(lab, idx);
Steve Eddins has a great blog post relating to this here: http://blogs.mathworks.com/steve/2009/02/27/using-ismember-with-the-output-of-regionprops/
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!