Open-CV 2.4 Android-Java:
我已经像这样搜索轮廓(MatofPoint 列表):
Imgproc.findContours(roi_mat, contours, hierarchy, cfg.retMode, cfg.apxMode);
然后是凸包(必须是 MatofInt 的列表)
for (int k=0; k < contours.size(); k++){
Imgproc.convexHull(contours.get(k), hull.get(k));
}
convexhull 需要一个 MatofInt,但 drawcontours 需要一个 MatofPoint..那该怎么办?
提前致谢..
编辑:@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);
最佳答案
看起来 OpenCV Java API 缺少另一个 convexHull() 签名:
convexHull(MatOfPoint points, MatOfPoint hull);
好像可以用 C++ 调用。
虽然我们还没有添加它,但您需要手动创建 MatOfPoint 格式的hull:
- 使用
MatOfPoint::toArray()
或MatOfPoint::toList()
得到轮廓点 - 使用
MatOfInt::toArray()
或MatOfInt::toList()
获取他们的船体索引 - 创建一个新的
Point[]
或List<Point>
只有船体点 - 将其转换为
MatOfPoint
通过MatOfPoint::fromArray()
或MatOfPoint::fromList()
- 调用
Core.drawContours()
关于java - android java opencv 2.4 convexhull 凸缺陷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10961660/