gpt4 book ai didi

c# - 白色 Blob 检测

转载 作者:太空狗 更新时间:2023-10-29 19:48:05 28 4
gpt4 key购买 nike

我正在尝试使用 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 检测该白色 Blob ,我将非常感激。

上面的代码只检测边缘,所以它只会检测有锐边的形状,这种情况很少见。

编辑

我有点让它用下面的方法工作

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();
}

肯定有比使用固定宽度更好的方法(因为它们可能变化很大)

最佳答案

如果你想得到一个标记的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();
}

问我是否想要不同的东西,我会尽我所能提供帮助:)

关于c# - 白色 Blob 检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9794196/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com