如何在 AForge 中找到矩形内的圆圈

How to find circle inside Rectangle in AForge

我正在尝试在 AForge 中检测矩形内的圆。我已成功确定 Rectangles 但无法在 Rectangle 中找到 circles。如何在 AForge.

中找到另一个形状内的形状
string strPath = Server.MapPath("~/Recipt001.png");
Bitmap myBitmap = new Bitmap(strPath);

//Some filters Grayscale, invert, threshold

//Blod Filtering                      


BlobCounter blobCounter = new BlobCounter();
blobCounter.ProcessImage(temp);
blobCounter.ObjectsOrder = ObjectsOrder.YX;
blobCounter.FilterBlobs = true;

Blob[] blobs = blobCounter.GetObjectsInformation();
Graphics g = Graphics.FromImage(myBitmap);
Pen redPen = new Pen(Color.Red, 2);
SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

// dictionary of color to highlight different shapes
Dictionary<PolygonSubType, Color> colors = new Dictionary<PolygonSubType, Color>();

colors.Add(PolygonSubType.Unknown, Color.White);
colors.Add(PolygonSubType.Trapezoid, Color.Orange);
colors.Add(PolygonSubType.Parallelogram, Color.Red);
colors.Add(PolygonSubType.Rectangle, Color.Green);
colors.Add(PolygonSubType.Square, Color.Blue);
colors.Add(PolygonSubType.Rhombus, Color.Gray);

colors.Add(PolygonSubType.EquilateralTriangle, Color.Pink);
colors.Add(PolygonSubType.IsoscelesTriangle, Color.Purple);
colors.Add(PolygonSubType.RectangledTriangle, Color.SkyBlue);
colors.Add(PolygonSubType.RectangledIsoscelesTriangle, Color.SeaGreen);

for (int i = 0, n = blobs.Length; i < n; i++)
{
    List<IntPoint> corners;
    List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
    Point center;
    double radius;

    if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
    {
        if (shapeChecker.CheckPolygonSubType(corners) == PolygonSubType.Rectangle)
        {
            g.DrawPolygon(redPen, ToPointsArray(corners));
        }
    }
}

redPen.Dispose();
g.Dispose();

None 的图像处理库甚至 MATLAB 中的图像处理都可以让您在 ROI 中搜索 ROI(ROI - 感兴趣的区域,如矩形或圆形)。概念是 CROP REGION -> SEARCH OBJECTS IN REGION

所以首先找到主要的矩形,然后将图像裁剪成矩形并在其中执行圆形搜索。否则搜索所有圆和所有矩形,然后使用简单的数学将圆分类为属于哪个矩形。