简体   繁体   中英

How to find circle inside Rectangle in AForge

I am trying to detect Circle inside Rectangle in AForge . I have successfully determined Rectangles but unable to find circles inside Rectangle . How to find shape inside another shape in 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 of image processing libraries and even image processing in MATLAB lets you search ROI inside ROI ( ROI - region of intrest like rectangles or circles ). Concept is CROP REGION -> SEARCH OBJECTS IN REGION

So first locate primary rectangles, thereafter crop image to rectangles and perform circle search inside them. Otherwise search for all circles and all rectangles and then classify circles to be belonging to which rectangle using simple maths.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM