Ask Your Question
0

Convert MatOfPoint2f to MatOfPoint

asked 2015-05-09 03:05:05 -0600

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<>();
p.add(approxMatOfPoint);
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
0

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

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<>();
contourTemp.add(approxf1);
Imgproc.drawContours(img, contourTemp, 0, new Scalar(0, 255, 0), 2);

Cheers.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-05-09 03:05:05 -0600

Seen: 2,384 times

Last updated: May 13 '15