在 Matlab 中使用霍夫变换,检测到一些线条。使用这些线的端点我已经绘制了它们。当我拥有所有变量时,我无法理解如何找到相交线。
Line7
Point1 [50,66]
Point2 [11,106]
theta,rho [45,81]
Line9
Point1 [19,83]
Point2 [53,79]
theta,rho [82,84]
由于参数方程如下
rho = xCos(theta) + ySin(theta)
我不确定如何解决这个问题。有了所有这些信息,必须有一种快速的方法来查找线是否相交,如果相交,点也一样。
非常感谢任何指导。
function FindHoughLines(I,filename)
[H,T,R] = hough(I);
rotI = imrotate(I,0,'crop');
imshow(H,[],'XData',T,'YData',R,...
'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
P = houghpeaks(H,10,'threshold',ceil(0.1*max(H(:))));
x = T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');
% Find lines and plot them
lines = houghlines(I,T,R,P,'FillGap',5,'MinLength',7);
figure, imshow(rotI), hold on
max_len = 0;
for k = 1:length(lines)
if(isField(lines,'point1') ~= 0)
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');
text(xy(1,1),xy(1,2),[ num2str(k)],'HorizontalAlignment','center','BackgroundColor',[.7 .9 .7]);
% 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
end