Ask Your Question

Convert MatOfPoint2f to MatOfPoint

asked 2015-05-09 03:05:05 -0500

gmunumel gravatar image

I'm working in an opencv project for android. I need to convert a variable from MatOfPoint2f to MatOfPoint. As follows is the relevant part of my code: approx is of type MatOfPoint2f and I need to convert it because drawContours use type ArrayList<matofpoint>.

Imgproc.approxPolyDP(newMtx, approx, 0.02*peri, true);
approxMatOfPoint = (MatOfPoint) approx; // to convert
ArrayList<MatOfPoint> p = new ArrayList<>();
Imgproc.drawContours(img, p, 0, new Scalar(0,255,0), 2);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-05-13 02:34:52 -0500

gmunumel gravatar image

I got it working doing:

MatOfPoint approxf1 = new MatOfPoint();
Imgproc.approxPolyDP(newMtx, approx, 0.02 * peri, true);
// All these lines are to print the contour (optional)
approx.convertTo(approxf1, CvType.CV_32S);
List<MatOfPoint> contourTemp = new ArrayList<>();
Imgproc.drawContours(img, contourTemp, 0, new Scalar(0, 255, 0), 2);


edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-05-09 03:05:05 -0500

Seen: 1,901 times

Last updated: May 13 '15