如何在AForge中找到Rectangle中的圆

时间:2017-02-08 14:45:31

标签: c# aforge

我试图在AForge中检测矩形内的圆形。我已成功确定Rectangles但无法在circles内找到Rectangle。如何在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();

1 个答案:

答案 0 :(得分:1)

MATLAB中的图像处理库甚至图像处理都不能让您在ROI内部搜索ROI( ROI - 像矩形或圆圈这样的兴趣区域)。概念是 CROP REGION - &gt;搜索区域内的对象

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