Hier ist mein Code:Convex Rumpf Rückkehr java.lang.IndexOutOfBoundsException opencv android
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
alle die Kontur in dem Bild, das zuvor war abrufen mit findcontours.And largest_contour_index ein Index für die größten Konturen ist. Aber ich erhalte einen Ausnahmefehler bei:
Imgproc.convexHull(contours2.get(largest_contour_index), hull.get(largest_contour_index));
Können Sie sagen, wo das Problem?
Vielen Dank im Voraus für Ihre Hilfe
Ich empfehle Ihnen, es zu debuggen, um die Größe jeder Sammlung zu sehen: 'contures2' und' hull'. Weil entweder das eine oder das andere (oder sogar beide) keine "größten_Kontur_Index" -Elemente haben. – aribeiro
Ich finde den Fehler, ich füge nur einen Wert zum Rumpf hinzu, und wenn ich large_contour_index verwende, zeigt es nichts an. Mein schlechter, dummer Fehler – adams