将 MatOfPoint2f 转换为 MatOfPoint

Gab*_*mel 2 java android opencv

我正在为 android 开发一个 opencv 项目。我需要将变量从 转换MatOfPoint2fMatOfPoint。以下是我的代码的相关部分:approxis of type MatOfPoint2f,我需要转换它,因为drawContours使用 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);
Run Code Online (Sandbox Code Playgroud)

Gab*_*mel 6

我解决了以下问题:

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);
Run Code Online (Sandbox Code Playgroud)

干杯。