我目前有一行代码
List<MatOfPoint> contours = new Vector<MatOfPoint>();
我希望转换为MatOfPoint2f
,以便我可以调用以下函数:
Imgproc.arcLength(contours, true);
但是,我真的不确定如何将List<MatOfPoint>
转换为MatOfPoint2f
,contours
必须与arcLength
合作。谁能告诉我怎么做?
答案 0 :(得分:3)
似乎你想要:
List<MatOfPoint> contours; //already initialized somewhere in your code
List<MatOfPoint2f> newContours = new ArrayList<>();
for(MatOfPoint point : contours) {
MatOfPoint2f newPoint = new MatOfPoint2f(point.toArray());
newContours.add(newPoint);
}