Ask Your Question
0

Function ConvexHull not work in Android

asked 2013-05-30 10:59:30 -0500

WS gravatar image
    // In C++
    ...
    convexHull( Mat(v[layer]), v[layer], false );
    v[layer]=v[layer]; // OK

    // In Java (Android)
    ...
    MatOfInt mOi=new MatOfInt();
    Imgproc.convexHull( matOfPoint, mOi );
    List<Point> l = new ArrayList<Point>();
    for (int i=0; i<mOi.toArray().length-1; i+=2) // Neither with toList()
        l.add(new Point(mOi.toArray()[i],mOi.toArray()[i+1]));
    maOfPoint.fromList(l);

The problem is that it works, but not with the desired result. Generates random polygons. Thanks for your attention and greetings. WS

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-09-17 06:51:30 -0500

Try it like that :

MatOfInt mOi= new MatOfInt();
Imgproc.convexHull(matOfPoint, mOi); 
        int[] intlist = mOi.toArray();
        List<Point> l = new ArrayList<Point>();
        l.clear();
        for (int i = 0; i < intlist.length; i++) {
            l.add(matOfPoint.toList().get(mOi.toList().get(i)));
}
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-05-30 10:59:30 -0500

Seen: 1,414 times

Last updated: Sep 17 '13