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
java android opencv


source to share


No one has answered this question yet

See similar questions:

31
How to convert MatOfPoint to MatOfPoint2f in opencv java api

or similar:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
1116
Android SDK installation not finding JDK
0
Cannot execute approxPolyDp function in OpenCV



All Articles
Loading...
X
Show
Funny
Dev
Pics