android java opencv 2.4 convexhull convexdefect

ddd*_*ddd 7 java android opencv convex-hull

Open-CV 2.4 Android-Java:

我搜索了等高线(MatofPoint列表),如下所示:

Imgproc.findContours(roi_mat, contours, hierarchy, cfg.retMode, cfg.apxMode);
Run Code Online (Sandbox Code Playgroud)

然后是凸壳(必须是MatofInt的列表)

for (int k=0; k < contours.size(); k++){

     Imgproc.convexHull(contours.get(k), hull.get(k));
}
Run Code Online (Sandbox Code Playgroud)

凸壳需要一个MatofInt,但是drawcontours想要一个MatofPoint ..那么该怎么办?

Thx提前..


编辑:@ OpenCV4Android

for (int k=0; k < contours.size(); k++){
    Imgproc.convexHull(contours.get(k), hullInt);

    for(int j=0; j < hullInt.toList().size(); j++){
        hullPointList.add(contours.get(k).toList().get(hullInt.toList().get(j)));
    }

    hullPointMat.fromList(hullPointList);
    hullPoints.add(hullPointMat);   
}

Imgproc.drawContours( mROI, hullPoints, -1,  new Scalar(255,0,0, 255), 1);
Run Code Online (Sandbox Code Playgroud)

小智 4

看起来 OpenCV Java API 缺少另一个凸包()签名:

convexHull(MatOfPoint points, MatOfPoint hull);
Run Code Online (Sandbox Code Playgroud)

就像可以在 C++ 中调用一样。

虽然我们还没有添加它,但您需要手动创建 MatOfPoint 格式的船体

  • 使用MatOfPoint::toArray()MatOfPoint::toList()获取轮廓点
  • 使用MatOfInt::toArray()MatOfInt::toList()获取船体索引
  • 创建一个新的Point[]List<Point>仅使用船体的点
  • 将其转换为MatOfPoint通过MatOfPoint::fromArray()MatOfPoint::fromList()
  • 称呼Core.drawContours()