Optical Mark Recognition using C#

1.1k views Asked by At

This is a function which determines if a point is within the boundary of the image and checks if it overlaps with other circle.

If it returns true then i check the threshold of the circle filled black and later save the point which is filled more than 90% into a list of points.

My program works in 2 steps

1) If it forms a circle with no overlaping.

2) If it is 90% filled.

I am facing a error that if i pass a image with only 1 circle it saves 1408 circles.I have no idea what i am doing wrong.

Below is the button click event

        for (int i = 0; i < 50; i++)
        {
            for (int j = 0; j < 50; j++)
            {
                p.X = j;
                p.Y = i;
                if  (isCircle(p))
                {

                    if (checkThreshold(p) > 90)
                    {
                        pts.Insert(0, p);
                    }
                }
            }
        }

Below given are the functions

private bool isCircle(Point p)
    {

        double count = 0;
        Point curP = new Point();
        //Point centre = new Point(24, 20);
        int a = 0;

        boundary.X = 50;
        boundary.Y = 50;

        for (int x = (p.X - radius); x <= (p.X - radius); x++)
        {
            for (int y = (p.Y - radius); y <= (p.Y - radius); y++)
            {
                if ((x < boundary.X) && (y < boundary.Y) && (x + radius < boundary.X) && (y + radius < boundary.Y))
                {
                    curP.X = 0;
                    curP.Y = 0;

                    curP.X = x;
                    curP.Y = y; //stores new point to be sent in curP
                    while (a < pts.Count)
                    {
                        //point , centre, radius
                        if (checkOverlap(curP, pts[a], radius) == false) //send point to check if it overlaps or not
                        {
                            // MessageBox.Show("yellow");
                            count = 1;
                            break;
                        }
                        else
                        {
                            a++;
                        }

                    }

                }
                if (count == 1)
                    break;
            }
            if (count == 1)
                break;

        }

        if (count == 1)
            return true;

        else return false;
    }

Below given is the checkOverlap function

    private bool checkOverlap(Point p, Point c, int radii)
    {

        Point listPoint;

        listPoint = p;

        //the following if condition checks if the point resides in the list or not

        if ((((c.X - radii) < listPoint.X) && (listPoint.X > (c.X - radii))) && (((c.Y - radii) < listPoint.Y) && (listPoint.Y > (c.Y - radii))))
        {
            if ((((p.X - c.X) * (p.X - c.X)) - ((p.Y - c.Y) * (p.Y - c.Y))) < (radius * radius))
            {
                return false;
            }
            return true;
        }
        else
            return true;
    }
1

There are 1 answers

0
Adam Finley On

Not sure if this is THE issue, but your count variable should be an int due to the way you are testing for equality.