如何从List <matofpoint>转换为MatOfPoint2f?</matofpoint>

时间:2015-03-27 13:51:43

标签: java opencv

我目前有一行代码

List<MatOfPoint> contours = new Vector<MatOfPoint>();

我希望转换为MatOfPoint2f,以便我可以调用以下函数:

Imgproc.arcLength(contours, true);

但是,我真的不确定如何将List<MatOfPoint>转换为MatOfPoint2fcontours必须与arcLength合作。谁能告诉我怎么做?

1 个答案:

答案 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);
 }