Ask Your Question

Revision history [back]

Filled circle are not detecting

Hello, I am new to opencv and trying to make omr scanner from scratch and have snippet which is supposed to detect filled circles but it is doing quite opposite and detecting unfilled circle. Please show me my mistake in the code.

 public void showFilledCircles(Bitmap paramView)
{
    paramView = BitmapFactory.decodeFile(filename);
    Mat localMat1 = new Mat();
    Utils.bitmapToMat(paramView, localMat1);
    Object localObject1 = new Mat();
    double[] lo;
    Imgproc.GaussianBlur(localMat1, (Mat)localObject1, new Size(3.0D, 3.0D), 3.0D, 2.5D);
    Mat localMat2 = new Mat();
    Imgproc.cvtColor((Mat)localObject1, localMat2, 7);
    localObject1 = new ArrayList();
    Object localObject2 = new Mat();
    Mat localMat3 = new Mat();
    Imgproc.Canny(localMat2, localMat3, 140.0D, 255.0D);
    Imgproc.findContours(localMat3, (List)localObject1, (Mat)localObject2,1,2);
    int i = 0;
    while (i < ((List)localObject1).size())
    {
        Imgproc.drawContours(localMat2, (List)localObject1, i, new Scalar(0.0D, 0.0D, 255.0D), 2);
        //Log.i("Local Objects","Local Object Point -------------------"+localMat2);
        i += 1;
    }
    localObject1 = new Mat();
    Core.inRange(localMat2, new Scalar(70.0D, 70.0D, 70.0D), new Scalar(255.0D, 255.0D, 255.0D), (Mat)localObject1);
    localMat2 = localMat1.clone();
    Imgproc.HoughCircles((Mat)localObject1, localMat2, 3, 1.0D, 20.0D, 40.0D, 10.0D, 6, 18);

    i = 0;
    for (;;)
    {
        if (i < localMat2.cols())
        {
            localObject1 = localMat2.get(0, i);
            lo = localMat2.get(0, i);
            if (localObject1 != null) {}
        }
        else
        {
            Utils.matToBitmap(localMat1, paramView);
            this.imageView.setImageBitmap(paramView);
            //this.imageView.setRotation(90.0F);
            return;
        }
        localObject2 = new Point(Math.round(lo[0]), Math.round(lo[1]));
        int j = (int)Math.round(lo[2]);
        Log.i("cicle Points ---------", localObject2 + " radius " + j);
        Imgproc.circle(localMat1, (Point)localObject2, 1, new Scalar(0.0D, 0.0D, 255.0D), 5);
        Imgproc.circle(localMat1, (Point)localObject2, j, new Scalar(255.0D, 0.0D, 0.0D), 5);
        i += 1;
    }
}

Image of omr output image description

click to hide/show revision 2
retagged

updated 2017-06-27 04:16:29 -0600

berak gravatar image

Filled circle are not detecting

Hello, I am new to opencv and trying to make omr scanner from scratch and have snippet which is supposed to detect filled circles but it is doing quite opposite and detecting unfilled circle. Please show me my mistake in the code.

 public void showFilledCircles(Bitmap paramView)
{
    paramView = BitmapFactory.decodeFile(filename);
    Mat localMat1 = new Mat();
    Utils.bitmapToMat(paramView, localMat1);
    Object localObject1 = new Mat();
    double[] lo;
    Imgproc.GaussianBlur(localMat1, (Mat)localObject1, new Size(3.0D, 3.0D), 3.0D, 2.5D);
    Mat localMat2 = new Mat();
    Imgproc.cvtColor((Mat)localObject1, localMat2, 7);
    localObject1 = new ArrayList();
    Object localObject2 = new Mat();
    Mat localMat3 = new Mat();
    Imgproc.Canny(localMat2, localMat3, 140.0D, 255.0D);
    Imgproc.findContours(localMat3, (List)localObject1, (Mat)localObject2,1,2);
    int i = 0;
    while (i < ((List)localObject1).size())
    {
        Imgproc.drawContours(localMat2, (List)localObject1, i, new Scalar(0.0D, 0.0D, 255.0D), 2);
        //Log.i("Local Objects","Local Object Point -------------------"+localMat2);
        i += 1;
    }
    localObject1 = new Mat();
    Core.inRange(localMat2, new Scalar(70.0D, 70.0D, 70.0D), new Scalar(255.0D, 255.0D, 255.0D), (Mat)localObject1);
    localMat2 = localMat1.clone();
    Imgproc.HoughCircles((Mat)localObject1, localMat2, 3, 1.0D, 20.0D, 40.0D, 10.0D, 6, 18);

    i = 0;
    for (;;)
    {
        if (i < localMat2.cols())
        {
            localObject1 = localMat2.get(0, i);
            lo = localMat2.get(0, i);
            if (localObject1 != null) {}
        }
        else
        {
            Utils.matToBitmap(localMat1, paramView);
            this.imageView.setImageBitmap(paramView);
            //this.imageView.setRotation(90.0F);
            return;
        }
        localObject2 = new Point(Math.round(lo[0]), Math.round(lo[1]));
        int j = (int)Math.round(lo[2]);
        Log.i("cicle Points ---------", localObject2 + " radius " + j);
        Imgproc.circle(localMat1, (Point)localObject2, 1, new Scalar(0.0D, 0.0D, 255.0D), 5);
        Imgproc.circle(localMat1, (Point)localObject2, j, new Scalar(255.0D, 0.0D, 0.0D), 5);
        i += 1;
    }
}

Image of omr output image description