我有一个List变量'l',其值如下:
List<Point> l = new ArrayList<Point>();
Imgproc.convexHull(contours,hull);
for (int j = 0; j < intlist.length; j++) {
l.add(contours.toList().get(hull.toList().get(j)));
}
在此之后,我得到以下l:
的值l = [{1,2}, {3,4}, {5,6}]
等等。如何在l.get(i)中找到所有i的第1和第2值的平均值,作为数组。例如,对于上述内容,我需要以下内容:
x = 3
y = 4
答案 0 :(得分:0)
最后我得到了答案!下面的代码将完成这项工作:
double sum_x = 0;
double sum_y = 0;
int j;
for (j = 0; j < hull.size().height; j++) {
l.add(contours.toList().get(hull.toList().get(j)));
sum_x += l.get(j).x;
sum_y += l.get(j).y;
}
x = sum_x / j;
y = sum_y / j;