How to Find rectangular region using hough line in Matlab?

1 Ansicht (letzte 30 Tage)
Adrian
Adrian am 18 Dez. 2014
I use this code but did't finded plate region. How do I find the plate ?
This code gives only horizontal lines but I must find vertical and horizontal lines.
I = imread('image.jpg');
I= rgb2gray(I);
%I(:,1:2)=0;
%I(1,:)=0;
%I(end,:)=0;
%I(:,end)=0;
BW = edge(I,'canny');
%imshow(BW)
[H,T,R] = hough(BW);
%{
imshow(H,[],'XData',T,'YData',R,...
'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
%}
P = houghpeaks(H, 20,'NHoodSize',[1 1],'threshold',ceil(0.1*max(H(:))));
lines = houghlines(BW, T, R, P, 'FillGap', 40, 'MinLength', 1);
%P = houghpeaks(H,7,'NHoodSize','threshold',ceil(0.4*max(H(:))));
%lines = houghlines(BW,T,R,P,'FillGap',40,'MinLength',90);
x = T(P(:,2)); y = R(P(:,1));
%plot(x,y,'s','color','blue');
% Find lines and plot them
figure;
imagesc(I);hold on;colormap gray;
axis image;
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
% 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')
plot(xy(1,1),xy(2,2),'x','LineWidth',2,'Color','blue');
%plot(xy(2,2),xy(2,2),'x','LineWidth',2,'Color','green');
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green'); %connect red and blue point
% 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
This part draws connect red and blue point. How to connect blue blue point and red red point ? If I can it , I find plate area.
% 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')
plot(xy(1,1),xy(2,2),'x','LineWidth',2,'Color','blue');
%plot(xy(2,2),xy(2,2),'x','LineWidth',2,'Color','green');
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green'); %connect red and blue point
then , Probably this part change.
lines = houghlines(BW, T, R, P, 'FillGap', 40, 'MinLength', 90);
input :
output :

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by