![]() |
OpenCV 4.13.0
Open Source Computer Vision
|
列挙型 | |
| enum | cv::KmeansFlags { cv::KMEANS_RANDOM_CENTERS = 0 , cv::KMEANS_PP_CENTERS = 2 , cv::KMEANS_USE_INITIAL_LABELS = 1 } |
| k-meansフラグ 続き... | |
関数 | |
| 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-meansフラグ
| double cv::kmeans | ( | InputArray | data, |
| int | K, | ||
| InputOutputArray | bestLabels, | ||
| TermCriteria | criteria, | ||
| int | attempts, | ||
| int | flags, | ||
| OutputArray | centers = noArray() ) |
| Python: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| cv.kmeans( | data, K, bestLabels, criteria, attempts, flags[, centers] | ) -> | retval, bestLabels, centers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <opencv2/core.hpp>
クラスタの中心を求め、入力サンプルをクラスタの周囲にグループ化する。
関数kmeansは、cluster_count個のクラスタの中心を求め、入力サンプルをそれらのクラスタの周りにグループ化するk-meansアルゴリズムを実装する。出力として、\(\texttt{bestLabels}_i\) には、samples行列の \(i^{th}\) 行に格納されたサンプルの0始まりのクラスタインデックスが格納される。
| data | クラスタリング対象のデータ。浮動小数点座標を持つN次元点の配列が必要である。この配列の例としては次のものがある:
|
| K | 集合を分割するクラスタ数。 |
| bestLabels | 各サンプルのクラスタインデックスを格納する入出力用の整数配列。 |
| criteria | アルゴリズムの終了条件、すなわち最大反復回数および/または希望する精度。精度は criteria.epsilon として指定する。ある反復で各クラスタ中心の移動量が criteria.epsilon 未満になった時点で、アルゴリズムは停止する。 |
| attempts | 異なる初期ラベリングを用いてアルゴリズムを実行する回数を指定するフラグ。アルゴリズムは最良のコンパクトさをもたらすラベルを返す(最後の関数引数を参照)。 |
| flags | cv::KmeansFlags の値を取り得るフラグ |
| centers | クラスタ中心を出力する行列。各行が1つのクラスタ中心に対応する。 |
\[\sum _i \| \texttt{samples} _i - \texttt{centers} _{ \texttt{labels} _i} \| ^2\]
after every attempt. The best (minimum) value is chosen and the corresponding labels and the compactness value are returned by the function. Basically, you can use only the core of the function, set the number of attempts to 1, initialize labels each time using a custom algorithm, pass them with the ( flags = KMEANS_USE_INITIAL_LABELS ) flag, and then choose the best (most-compact) clustering.| int cv::partition | ( | const std::vector< _Tp > & | vec, |
| std::vector< int > & | labels, | ||
| _EqPredicate | predicate = _EqPredicate() ) |
#include <opencv2/core/operations.hpp>
要素集合を同値類に分割する。
汎用関数partitionは、http://en.wikipedia.org/wiki/Disjoint-set_data_structure に記載されているように、\(N\) 個の要素からなる集合を1つ以上の同値類に分割する \(O(N^2)\) のアルゴリズムを実装する。この関数は同値類の数を返す。
| vec | ベクトルとして格納された要素の集合。 |
| labels | ラベルの出力ベクトル。vecと同じ数の要素を含む。各ラベルlabels[i]は vec[i] の0始まりのクラスタインデックスである。 |
| predicate | 同値述語(2引数のブール関数へのポインタ、またはメソッド bool operator()(const _Tp& a, const _Tp& b) を持つクラスのインスタンス)。この述語は要素が確実に同じクラスに属するときtrueを返し、同じクラスに属するか否か不明な場合はfalseを返す。 |