【问题标题】:Hough Peak detection霍夫峰值检测
【发布时间】:2018-08-16 23:44:49
【问题描述】:

我已经实现了霍夫峰值检测。输出如下:

我们可以看到红色线与画布的两侧(左、右)相交。

如何限制检测到的线与源线之间的长度?

例如,

源代码

public class Line
{
    public Point Start { get; set; }
    public Point End { get; set; }

    public Line(Point start, Point end)
    {
        Start = start;
        End = end;
    }
}

public class HoughLineTransform
{
    public HoughMap Accumulator { get; set; }

    public HoughLineTransform()
    {
    }

    public List<Line> GetLines(int threshold)
    {
        if (Accumulator == null)
        {
            throw new Exception("HoughMap is null");
        }

        int houghWidth = Accumulator.Width;
        int houghHeight = Accumulator.Height;
        int imageWidth = Accumulator.Image.Width;
        int imageHeight = Accumulator.Image.Height;

        List<Line> lines = new List<Line>();

        if (Accumulator == null)
            return lines;

        for (int rho = 0; rho < houghWidth; rho++)
        {
            for (int theta = 0; theta < houghHeight; theta++)
            {
                if ((int)Accumulator[rho, theta] >= threshold)
                {
                    int peak = Accumulator[rho, theta];

                    for (int ly = -4; ly <= 4; ly++)
                    {
                        for (int lx = -4; lx <= 4; lx++)
                        {
                            if ((ly + rho >= 0 && ly + rho < houghWidth) && (lx + theta >= 0 && lx + theta < houghHeight))
                            {
                                if ((int)Accumulator[rho + ly, theta + lx] > peak)
                                {
                                    peak = Accumulator[rho + ly, theta + lx];
                                    ly = lx = 5;
                                }
                            }
                        }
                    }

                    if (peak > (int)Accumulator[rho, theta])
                        continue;

                    int x1, y1, x2, y2;
                    x1 = y1 = x2 = y2 = 0;

                    double rad = theta * Math.PI / 180;

                    if (theta >= 45 && theta <= 135)
                    {
                        x1 = 0;
                        y1 = (int)(((double)(rho - (houghWidth / 2)) - ((x1 - (imageWidth / 2)) * Math.Cos(rad))) / Math.Sin(rad) + (imageHeight / 2));
                        x2 = imageWidth - 0;
                        y2 = (int)(((double)(rho - (houghWidth / 2)) - ((x2 - (imageWidth / 2)) * Math.Cos(rad))) / Math.Sin(rad) + (imageHeight / 2));
                    }
                    else
                    {
                        y1 = 0;
                        x1 = (int)(((double)(rho - (houghWidth / 2)) - ((y1 - (imageHeight / 2)) * Math.Sin(rad))) / Math.Cos(rad) + (imageWidth / 2));
                        y2 = imageHeight - 0;
                        x2 = (int)(((double)(rho - (houghWidth / 2)) - ((y2 - (imageHeight / 2)) * Math.Sin(rad))) / Math.Cos(rad) + (imageWidth / 2));
                    }

                    lines.Add(new Line(new Point(x1, y1), new Point(x2, y2)));
                }
            }
        }

        return lines;
    }
}

相关:Hough Line Transform implementation

【问题讨论】:

  • 由于 HT 的性质,它会给你一个没有段信息的线的峰值。 (例如:你会有一个类似的虚线 HT 映射)。现在,如果您想检测线段,您可以尝试扫描线的接近度(取决于 HT 分辨率)并确定(大多数)点的位置。

标签: c# image-processing hough-transform


【解决方案1】:

一种简单的方法是在原始图像上叠加生成的轮廓线并检查像素重叠的位置(使用特定窗口)。

如果它们开始或结束重叠,则您有线段的开始/结束。

顺便说一句:我没有检查过你的算法,但我自己在大约 15 年前写了一个。我记得有一种迭代方法,您可以一次找到一条线(只是累积图像中的最大值)。 找到一条线后,删除该线的累积像素,然后通过找到最大值重新开始。 然后,您会找到第二重要的行。以此类推。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-29
    • 2013-03-09
    • 2015-05-03
    • 2020-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多