我想要实现的是这个 https://sites.google.com/a/vt.edu/motion-vision/home/license-plate-detection-by-hough-transform 我通过检测霍夫线。但是在这一步之后我无法理解这个程序 "现在,通过设置高度和宽度的比率,可以找到可能的水平和垂直对,以指示牌照周围的那些线段。结果如图4所示。" ..有人向我解释或添加代码会有所帮助。
我的代码:
clc
RGB = imread('new.jpg'); %Load image
[I2, rect] = imcrop(RGB);
I = rgb2gray(I2); %Convert image to Gray
%imshow(I); %Show image
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,'threshold',ceil(0.1*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',20);
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
%[I2, rect] = imcrop(I);
%figure, imshow(I2);