【问题标题】:Detecting intersecting lines after a hough transform在霍夫变换后检测相交线
【发布时间】:2012-04-27 18:50:51
【问题描述】:

在 Matlab 中使用 Hough 变换,检测到一些线条。使用这些线的端点我已经绘制了它们。当我拥有所有变量时,我无法理解如何找到相交线。

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

【问题讨论】:

标签: matlab hough-transform line-intersection parametric-equations


【解决方案1】:

想到的最直接的方法是使用将所有检测到的线转换为笛卡尔坐标

y = -ctg(theta) + r/sin(theta)

然后使用标准检测程序,例如http://en.wikipedia.org/wiki/Bentley–Ottmann_algorithm

【讨论】:

    【解决方案2】:

    您想要线线段的交点吗?例如,假设您的一条线段具有端点 (1,0) 和 (2,0),而另一条线段具有端点 (0,1) 和 (0,2);是否要计算 (0,0) 处的交叉点?

    你需要高效地处理多条线的情况并找到它们的所有交点,还是可以考虑所有线对并一一检查?

    最简单的情况是,如果只考虑成对的线,并且线(相对于线段)交叉点是否足够好。然后对于每对线,您只需求解两个联立线性方程:aX+bY=c,dX+eY=f。这是非常标准的做法;它相当于反转一个 2x2 矩阵。

    如果您需要注意交叉点何时实际上不在给定的线段内,这里有几种方法。 (1) 首先是上述交叉点,然后检查它是否位于每个给定段内。您可以通过选择一个坐标(例如 x 坐标)并查看它是否位于两个端点的 x 坐标之间来做到这一点。当然,您不能将 x 坐标用于垂直线,也不应将其用于近乎垂直的线;最好选择系数较大的坐标。 (2) 将线参数化写为 (x,y)=(x1,y1)+t(dx1,dx1) 和 (x,y)=(x2,y2)+u(dx2,dy2);现在代替 x,y 的联立方程你有 t,u 的联立方程;解决这些问题并检查 0

    如果你需要在行数多的情况下高效处理,有算法可以解决这个问题; google "line sweep" 找到一个很容易理解的标准。

    【讨论】:

    • 感谢您的回答。实际上我有很多线,我想找到线的交点而不是线段。实际相交的线。
    猜你喜欢
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    相关资源
    最近更新 更多