Detecting Particular line and circle.
2 views (last 30 days)
Show older comments
Hi guys this is my code. my task is to detect white line in green field and yellow goal post and orange ball. I am unable to detect the ball and yellow line and it is detecting all white line. i just want green field white line should get detected and yellow goal post and orange ball. PLEASE HELP ME THANK YOU.
imread ('C:\Users\new\Desktop\Ass1\robocup_image1.jpeg');
img = imread ('C:\Users\new\Desktop\Ass1\robocup_image1.jpeg');
imshow (img);
RGB = imread ('C:\Users\new\Desktop\Ass1\robocup_image1.jpeg');
imshow (RGB);
I = rgb2gray(RGB);
imshow(I)
BW = edge(I,'Canny');
imshow(BW)
[H,theta,rho] = hough(BW);
figure, imshow(imadjust(mat2gray(H)),[],'XData',theta,'YData',rho,...
'InitialMagnification','fit');
xlabel('\theta (degrees)'), ylabel('\rho');
axis on, axis normal, hold on;
colormap(hot)
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','black');
lines = houghlines(BW,theta,rho,P,'FillGap',5,'MinLength',7);
figure, imshow(BW), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
0 Comments
Answers (1)
Image Analyst
on 8 May 2015
See my color segmentation routines in my File Exchange http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
In addition see attachment where I track a green Sharpie marker.
0 Comments
See Also
Categories
Find more on Import, Export, and Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!