OpenCV on Android - Imgproc.minEnclosingCircle and Core.circle

I am having a problem with the relationship between Imgproc.minEnclosingCircle method and Core.circle method. Below is what some of my code looks like:

/// Start of Code

//init
    List<MatOfPoint2f> contours2f   = new ArrayList<MatOfPoint2f>();
    List<MatOfPoint2f> polyMOP2f    = new ArrayList<MatOfPoint2f>();
    List<MatOfPoint> polyMOP        = new ArrayList<MatOfPoint>();
    Rect[] boundRect    = new Rect[contours.size()];
    Point[] mPusat      = new Point[contours.size()];
    float[] mJejari     = new float[contours.size()];

//initialize the Lists ?
    for (int i = 0; i < contours.size(); i++) {
        contours2f.add(new MatOfPoint2f());
        polyMOP2f.add(new MatOfPoint2f());
        polyMOP.add(new MatOfPoint());
    }

//Convert to MatOfPoint2f + approximate contours to polygon + get bounding rects and circles
    for (int i = 0; i < contours.size(); i++) {
        contours.get(i).convertTo(contours2f.get(i), CvType.CV_32FC2);
        Imgproc.approxPolyDP(contours2f.get(i), polyMOP2f.get(i), 3, true);
        polyMOP2f.get(i).convertTo(polyMOP.get(i), CvType.CV_32S);
        boundRect[i] = Imgproc.boundingRect(polyMOP.get(i));
        Imgproc.minEnclosingCircle(polyMOP2f.get(i), mPusat[i], mJejari);
    }

// Draw polygonal contours + boundingRects + circles
    for (int i = 0; i < contours.size(); i++) {
        Imgproc.drawContours(image3, polyMOP, i, green, 1);
        Core.rectangle(image3, boundRect[i].tl(), boundRect[i].br(), green, 2);
        Core.circle(image3, mPusat[i], (int)mJejari[i], green, 3);
    }

/// End of Code

      

I tried to run the program but got an error with an exception java.lang.NullPointerException

Then I tried to change the method Imgproc.minEnclosingCircle()

something like this:

...
    Imgproc.minEnclosingCircle(polyMOP2f.get(i), mPusat[i], tempJejari);
    mJejari[i] = tempJejari[0];
...

      

but that didn't work either.

My question is, it looks like the method Imgproc.minEnclosingCircle()

requires the radius (in my code it mJejari

) to report a float [] array, but the Core.circle () method requires the radius to be an integer. So, is there a way to manipulate the method Imgproc.minEnclosingCircle()

to satisfy the method Core.circle()

? Thanks earlier.

PS: some sources I used for the code: http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html

How to convert MatOfPoint to MatOfPoint2f in opencv java api

+3


source to share





All Articles