1

I am pretty new to OpenCV, and am using a Java wrapper of OpenCV. In my application I am detecting contours and then making convexHull around it. Imgproc.convexHell(matofpoint, matofint); provides me with hull values in MatOfInt form.

Now I wanna print matofint in my image, but the Imgproc. drawContour() require MatOfPoint.

So my question is how to convert MatOfInt to MatOfPoint

Prazzy Kumar
  • 994
  • 1
  • 11
  • 16
  • 1
    possible duplicate of [Convex Hull on Java Android Opencv 2.3](http://stackoverflow.com/questions/17586948/convex-hull-on-java-android-opencv-2-3) – Aurelius Mar 05 '14 at 19:49
  • Take a look at the second part of [this](http://stackoverflow.com/a/17618897/1601291) answer. It should explain your issue. – Aurelius Mar 05 '14 at 19:49
  • Tried everything,but none is working!!! :o – Prazzy Kumar Mar 05 '14 at 19:58
  • 2
    Perhaps you should update your question with (minimal) code demonstrating what you have tried. That way people can see what you've done, and correct errors you may have made. – Aurelius Mar 05 '14 at 20:02

1 Answers1

3
public static MatOfPoint convertIndexesToPoints(MatOfPoint contour, MatOfInt indexes) {
    int[] arrIndex = indexes.toArray();
    Point[] arrContour = contour.toArray();
    Point[] arrPoints = new Point[arrIndex.length];

    for (int i=0;i<arrIndex.length;i++) {
        arrPoints[i] = arrContour[arrIndex[i]];
    }

    MatOfPoint hull = new MatOfPoint(); 
    hull.fromArray(arrPoints);
    return hull; 
}
Alexander233
  • 390
  • 3
  • 12