【问题标题】:Get Number of lines in an image using AForge or OpenCV使用 AForge 或 OpenCV 获取图像中的行数
【发布时间】:2014-05-17 13:10:16
【问题描述】:

我正在尝试使用 C# 和 AForge 霍夫变换线检测来检测一条线是否穿过图像。在相同的上下文中,我正在考虑一种更好的解决方案,即检测图像是否清晰(无线条)然后返回错误值,反之亦然。我有下面的图片,我想检查线是否通过它,我会返回true,否则返回false:

http://s10.postimg.org/3sn8wari1/image.png

我使用下面的代码来获取行数,但似乎不准确或者我使用的算法不好。

        AForge.Imaging.Image.FormatImage(ref SEChild);
        // lock the source image
        BitmapData sourceData = SEChild.LockBits(
            new System.Drawing.Rectangle(0, 0, SEChild.Width, SEChild.Height),
            ImageLockMode.ReadOnly, SEChild.PixelFormat);
        // binarize the image
        UnmanagedImage binarySource = filter.Apply(new UnmanagedImage(sourceData));

        HoughLineTransformation lineTransform = new HoughLineTransformation();
        lineTransform. = 10;
        // apply Hough line transofrm
        lineTransform.ProcessImage(binarySource);
        HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity(0.5);
        if (lines.Count() > 0)
        {
            Result += "NW: Yes!\n";
        }
        else
        {
            Result += "NW: No!\n";
        }

【问题讨论】:

    标签: c# image-processing aforge hough-transform


    【解决方案1】:

    我应用了一个强大的解决方案,它对所有曲线除了直线。

    我使用了 AForge.net 库,之后使用了如下代码所示的步骤:

    1. 在图像上应用欧几里得颜色过滤
    2. 在结果图像上应用 Blob Counter 并获取在图像中找到的矩形 (Blob) 的数量。

    代码:

      private bool CheckLines(Bitmap image, Color filterColor)
        {
            EuclideanColorFiltering ColorFilter = new EuclideanColorFiltering();
            // set center colour and radius
            AForge.Imaging.RGB color = new RGB(filterColor.R, filterColor.G, filterColor.B, filterColor.A);
            ColorFilter.CenterColor = color;
            ColorFilter.Radius = 100;
            // Apply the filter
            ColorFilter.ApplyInPlace(image);
    
            // Define the Blob counter and use it!
            BlobCounter blobCounter = new BlobCounter();
            blobCounter.MinWidth = 5;
            blobCounter.MinHeight = 5;
            blobCounter.FilterBlobs = true;
            //blobCounter.ObjectsOrder = ObjectsOrder.Size;
            blobCounter.ProcessImage(image);
            System.Drawing.Rectangle[] rects = blobCounter.GetObjectsRectangles();
            if (rects.Length > 0)
            {
                return true;
            }
            return false;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-11
      • 1970-01-01
      • 1970-01-01
      • 2013-04-06
      • 2018-08-19
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多