凸壳返回java.lang.IndexOutOfBoundsException opencv android

时间:2016-04-02 21:54:20

标签: java android 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检索的图像中的所有轮廓。而maximum_contour_index是最大轮廓的索引。但是我收到了一个例外错误:

Imgproc.convexHull(contours2.get(largest_contour_index), hull.get(largest_contour_index));
你能说出问题出在哪里吗?

提前感谢您的帮助

0 个答案:

没有答案