白色斑点检测

问题描述 投票:8回答:1

我正在尝试使用AForge.NET来检测图像上的粗白线。

它就像我得到的管道,是应用阈值过滤器后的理想结果。

我知道如何检测形状,我已经这样做了,但是这在任何形状下都不匹配,因为它没有边缘而且不是圆形。

我有检测等边形状的示例代码,但我不知道这是否相关。

public void DetectQuadrilateralType(Bitmap bitmap)
{
    BlobCounter blobCounter = new BlobCounter();
    blobCounter.ProcessImage(bitmap);
    Blob[] blobs = blobCounter.GetObjectsInformation();
    //Graphics object to draw
    Pen pen;
    Graphics g = Graphics.FromImage(bitmap);
    SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

    for (int i = 0; i < blobs.Length; i++)
    {
        List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
        List<IntPoint> corners;

        if (i < edgePoints.ToArray().Length && i > -1)
        {
            try
            {
                if (shapeChecker.IsConvexPolygon(edgePoints, out corners))
                {
                    PolygonSubType subType = shapeChecker.CheckPolygonSubType(corners);

                    pen = new Pen(colors[subType], 2);
                    g.DrawPolygon(pen, ToPointsArray(corners));
                    pen.Dispose();
                }
            }
            catch (Exception e) { }
        }
    }
    g.Dispose();
}

这是我想要检测的图像:

enter image description here

如果有人知道如何用AForge检测那个白色斑点或者使用C#/ .NET我真的很感激它。

上面的代码只检测边缘,所以它只会检测到形状是否有尖锐的边缘,很少会出现这种情况。

编辑

我有点使用以下方法

public void DetectBigBlobs(Bitmap bitmap)
{
    BlobCounter blobCounter = new BlobCounter();
    blobCounter.ProcessImage(bitmap);
    Rectangle[] rects = blobCounter.GetObjectsRectangles();
    //Graphics object to draw
    Pen pen = new Pen(Color.Red, 2);
    Graphics g = Graphics.FromImage(bitmap);

    foreach (Rectangle rect in rects)
    {
        if (rect.Width > 200 && rect.Height > 150)
        {
            g.DrawRectangle(pen, rect);
        }
    }

    pen.Dispose();
    g.Dispose();
}

必须有比使用固定宽度更好的方法(因为它们可能会有很大差异)

c# .net image pattern-recognition aforge
1个回答
0
投票

如果你想得到一个标记的blob,你可以使用这个代码

public void DetectBigBlobs(Bitmap bitmap)
    {
        BlobCounter blobCounter = new BlobCounter();

        Graphics g = Graphics.FromImage(bitmap);

        //filtering the blobs before searching for blobs 
        blobCounter.FilterBlobs = true;
        blobCounter.MinHeight = bitmap.Height/3;
        blobCounter.MinWidth = bitmap.Width/3;

        blobCounter.ProcessImage(bitmap);
        Blob[] blobs = blobCounter.GetObjectsInformation();

        foreach (Blob b in blobs)
        { 
            //getting the found blob edgepoints 
            List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(b);
            //if you want to mark every edge point RED 
            foreach (IntPoint point in edgePoints)
                bitmap.SetPixel(point.X, point.Y, Color.Red);
            //if you want to draw a rectangle around the blob 
            g.DrawRectangle(Pens.Blue,b.Rectangle);

        }

        g.Dispose();
    }

问我是否想要不同的东西我会尽可能多的帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.