在 Java 中查找 List<Point> 的平均值

Find average of List<Point> in Java

我有一个列表变量 '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 的第一个和第二个值的平均值,作为一个数组。例如,对于上面的内容,我想要以下内容:

x = 3
y = 4

终于找到答案了!下面的代码将完成这项工作:

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;