我在将凸面缺陷放在框架上时遇到问题。为了计算它们,我修改了 c++ 源代码,这就是我归档的内容:
mConvexityDefectsMatOfInt4 = new MatOfInt4();
if(contours.size() > 0 && convexHullMatOfInt.rows() > 0)
Imgproc.convexityDefects(contours.get(0), convexHullMatOfInt, mConvexityDefectsMatOfInt4);
然而,Imgproc.drawContours(...) 方法要求作为参数传递给它的convexityDefects 将是ArrayList。我不知道如何进行转换。我对凸包也有类似的问题,但我发现了一个解决方法:
convexHullMatOfInt = new MatOfInt();
convexHullPointArrayList = new ArrayList<Point>();
convexHullMatOfPoint = new MatOfPoint();
convexHullMatOfPointArrayList = new ArrayList<MatOfPoint>();
//Calculate convex hulls
if(contours.size() > 0)
{
Imgproc.convexHull( contours.get(0), convexHullMatOfInt, false );
for(int j=0; j < convexHullMatOfInt.toList().size(); j++)
convexHullPointArrayList.add(contours.get(0).toList().get(convexHullMatOfInt.toList().get(j)));
convexHullMatOfPoint.fromList(convexHullPointArrayList);
convexHullMatOfPointArrayList.add(convexHullMatOfPoint);
}
凸面缺陷的类似解决方案不起作用。有谁知道我该如何解决这个问题?
如何从 MatOfInt4() 转换为 ArrayList() 才能绘制凸面缺陷?