![]() |
OpenCV 4.12.0
开源计算机视觉
|
枚举 | |
| 枚举 | cv::KmeansFlags { cv::KMEANS_RANDOM_CENTERS = 0 , cv::KMEANS_PP_CENTERS = 2 , cv::KMEANS_USE_INITIAL_LABELS = 1 } |
| k-均值标志 更多... | |
函数 | |
| double | cv::kmeans (InputArray data, int K, InputOutputArray bestLabels, TermCriteria criteria, int attempts, int flags, OutputArray centers=noArray()) |
| 查找簇的中心,并将输入样本围绕簇进行分组。 | |
| template<typename _Tp , class _EqPredicate > | |
| int | cv::partition (const std::vector< _Tp > &vec, std::vector< int > &labels, _EqPredicate predicate=_EqPredicate()) |
| 将元素集拆分为等价类。 | |
| enum cv::KmeansFlags |
#include <opencv2/core.hpp>
k-均值标志
| double cv::kmeans | ( | InputArray | data, |
| int | 输入的相机内参矩阵。, | ||
| InputOutputArray | bestLabels, | ||
| TermCriteria | criteria, | ||
| int | 尝试次数, | ||
| int | flags, | ||
| OutputArray | centers = noArray() ) |
| Python | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| cv.kmeans( | data, K, bestLabels, criteria, attempts, flags[, centers] | ) -> | retval, bestLabels, centers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <opencv2/core.hpp>
查找簇的中心,并将输入样本围绕簇进行分组。
函数 kmeans 实现了一种 k-均值算法,该算法查找 cluster_count 个簇的中心,并将输入样本围绕簇进行分组。作为输出,\(\texttt{bestLabels}_i\) 包含样本矩阵的第 \(i^{th}\) 行中存储的样本的从 0 开始的簇索引。
| data | 用于聚类的数据。需要一个具有浮点坐标的 N 维点数组。此数组的示例可以是
|
| 输入的相机内参矩阵。 | 将集合分割成的簇的数量。 |
| bestLabels | 输入/输出整数数组,用于存储每个样本的簇索引。 |
| criteria | 算法终止条件,即最大迭代次数和/或所需的精度。精度指定为 criteria.epsilon。一旦每个簇中心在某些迭代中移动小于 criteria.epsilon,算法就会停止。 |
| 尝试次数 | 标志,用于指定使用不同初始标签执行算法的次数。该算法返回产生最佳紧密度(参见最后一个函数参数)的标签。 |
| flags | 可以采用 cv::KmeansFlags 值的标志 |
| 输出检测到的中心点数组。 | 簇中心的输出矩阵,每个簇中心一行。 |
\[\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2\]
在每次尝试之后。选择最佳(最小)值,函数返回相应的标签和紧密度值。基本上,您可以只使用函数的核心,将尝试次数设置为 1,每次使用自定义算法初始化标签,使用( flags = KMEANS_USE_INITIAL_LABELS )标志传递它们,然后选择最佳(最紧凑)的聚类。| int cv::partition | ( | const std::vector< _Tp > & | vec, |
| std::vector< int > & | labels, | ||
| _EqPredicate | predicate = _EqPredicate() ) |
#include <opencv2/core/operations.hpp>
将元素集拆分为等价类。
通用函数 partition 实现了一种 \(O(N^2)\) 算法,用于将 \(N\) 个元素的集合分成一个或多个等价类,如 http://en.wikipedia.org/wiki/Disjoint-set_data_structure 中所述。该函数返回等价类的数量。
| vec | 存储为向量的元素集。 |
| labels | 标签的输出向量。它包含与 vec 一样多的元素。每个标签 labels[i] 都是 vec[i] 的从 0 开始的簇索引。 |
| predicate | 等价谓词(指向两个参数的布尔函数的指针,或具有方法 bool operator()(const _Tp& a, const _Tp& b) 的类的实例)。当元素肯定在同一个类中时,谓词返回 true,如果它们可能在或可能不在同一个类中,则返回 false。 |