Reputation: 994
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
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