0
这里是我的代码:凸包返回java.lang.IndexOutOfBoundsException OpenCV的机器人
public void findHull(){
int h = 0;
double area_Hull = 0;
hullArea = 0;
List<MatOfInt> hull = new ArrayList<MatOfInt>();
hull.add(new MatOfInt());
Imgproc.convexHull(contours2.get(largest_contour_index), hull.get(largest_contour_index));
Point[] points = new Point[hull.get(largest_contour_index).rows()];
for(h=0; h < hull.get(largest_contour_index).rows(); h++) {
int index = (int)hull.get(largest_contour_index).get(h, 0)[0];
points[h] = new Point(contours2.get(largest_contour_index).get(index, 0)[0],contours2.get(largest_contour_index).get(index, 0)[1]);
}
List<Point[]> hullpoints = new ArrayList<Point[]>();
hullpoints.add(points);
noOfDent = h;
List<MatOfPoint> hullmop = new ArrayList<MatOfPoint>();
MatOfPoint mop = new MatOfPoint();
mop.fromArray(hullpoints.get(0));
hullmop.add(mop);
area_Hull = Imgproc.contourArea(hullmop.get(0));
hullArea = area_Hull;
MatOfPoint2f Hullpt = new MatOfPoint2f();
hullmop.get(0).convertTo(Hullpt, CvType.CV_32FC2);
hullPerimeter=Imgproc.arcLength(Hullpt, false);
}
contours2
是这是以前检索使用findcontours.And largest_contour_index是最大的轮廓的索引图像中的所有轮廓。但我收到一个异常错误:
Imgproc.convexHull(contours2.get(largest_contour_index), hull.get(largest_contour_index));
你能告诉问题出在哪?
预先感谢您的帮助
我建议你调试它以查看每个集合的大小:'contours2'和'hull'。因为其中一个或其他(甚至两个)没有'largest_contour_index'元素。 – aribeiro
我发现错误,我只向船体添加一个值,并且当我使用largest_contour_index时,它不指向任何东西。我的坏,愚蠢的错误 – adams