Prazzy Kumar
Prazzy Kumar

Reputation: 994

Convert MatOfInt to MatofPoint

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

Upvotes: 1

Views: 2629

Answers (1)

Alexander233
Alexander233

Reputation: 390

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; 
}

Upvotes: 3

Related Questions