![]() |
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。 |