Reputation: 1876
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);
Upvotes: 3
Views: 3783
Reputation: 1876
I solved doing the following:
MatOfPoint approxf1 = new MatOfPoint();
...
Imgproc.approxPolyDP(newMtx, approx, 0.02*peri, true);
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.
Upvotes: 7