【问题标题】:How to get the Y-Coordinate of the cluster center?如何获得聚类中心的 Y 坐标?
【发布时间】:2019-06-22 23:03:57
【问题描述】:

我了解了 OpenCV 提供的 K-Means 聚类。该函数返回集群标签、集群中心和集群的整体紧凑度。

中心是 X 坐标。如何获取聚类中心的 Y 坐标?

这就是我对对象进行聚类的方法。

criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0)

compactness,labels,centers = cv2.kmeans(np.float32(x_coord_list), 6, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)

但它将中心返回为:

        [[646.8723  ]
     [111.409096]
     [803.1395  ]
     [495.14545 ]
     [235.57547 ]
     [349.85315 ]]

如何获得 Y 坐标?

【问题讨论】:

  • x_coord_list 1d?

标签: python opencv k-means


【解决方案1】:

显然,您调用 cv2.kmeans 时只使用了数据点的 x 坐标。

假设您还有一个列表 y_coord_list 代表您的点的 y 坐标,您可以使用:

# Z contains both coordinates, one per row as specified by the documentation
Z = np.vstack((x_coord_list, y_coord_list))
# convert Z to np.float32
Z = np.float32(Z)

compactness,labels,centers = cv2.kmeans(Z, 6, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)

【讨论】:

  • 有没有办法只使用 opencv 就可以知道最好的集群数量?
  • 我不知道。您可能想自己实现elbow method 之类的东西。
猜你喜欢
  • 2012-07-22
  • 2019-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-31
  • 1970-01-01
  • 2019-10-20
  • 1970-01-01
相关资源
最近更新 更多