OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項
cv::flann::GenericIndex< Distance > 類模板參考

FLANN 最近鄰索引類。此類的模板是用於構建索引的元素型別。 更多...

#include <opencv2/flann.hpp>

cv::flann::GenericIndex< Distance > 的協作圖

公共型別

typedef Distance::ResultType DistanceType
 
typedef Distance::ElementType ElementType
 

公共成員函式

 GenericIndex (const Mat &features, const ::cvflann::IndexParams &params, Distance distance=Distance())
 為給定資料集構造最近鄰搜尋索引。
 
 ~GenericIndex ()
 
const ::cvflann::IndexParams * getIndexParameters ()
 
::cvflann::IndexParams getParameters ()
 
void knnSearch (const Mat &queries, Mat &indices, Mat &dists, int knn, const ::cvflann::SearchParams &params)
 
void knnSearch (const std::vector< ElementType > &query, std::vector< int > &indices, std::vector< DistanceType > &dists, int knn, const ::cvflann::SearchParams &params)
 使用索引對給定查詢點執行 K-最近鄰搜尋。
 
int radiusSearch (const Mat &query, Mat &indices, Mat &dists, DistanceType radius, const ::cvflann::SearchParams &params)
 
int radiusSearch (const std::vector< ElementType > &query, std::vector< int > &indices, std::vector< DistanceType > &dists, DistanceType radius, const ::cvflann::SearchParams &params)
 使用索引對給定查詢點執行半徑最近鄰搜尋。
 
void save (String filename)
 
int size () const
 
int veclen () const
 

詳細描述

template<typename Distance>
class cv::flann::GenericIndex< Distance >

FLANN 最近鄰索引類。此類的模板是用於構建索引的元素型別。

Distance 仿函式指定用於計算兩點之間距離的度量。有幾種現成的 Distance 仿函式可用

cv::cvflann::L2_Simple - 平方歐幾里德距離仿函式。這是更簡單、展開的版本。對於非常低維的資料(例如 3D 點)更推薦使用此版本。

cv::flann::L2 - 平方歐幾里德距離仿函式,最佳化版本。

cv::flann::L1 - 曼哈頓距離仿函式,最佳化版本。

cv::flann::MinkowskiDistance - 閔可夫斯基距離仿函式。透過迴圈展開進行了高度最佳化。為了提高效率,末尾省略了平方根的計算。

cv::flann::MaxDistance - 最大距離仿函式。它計算兩個向量之間的最大距離。此距離不是有效的 kdtree 距離,它不是按維度累加的。

cv::flann::HammingLUT - 漢明距離仿函式。它使用查詢表實現來計算兩個字串之間的位差異。

cv::flann::Hamming - 漢明距離仿函式。如果可用,透過庫呼叫執行位計數。查詢表實現用作備選方案。

cv::flann::Hamming2 - 漢明距離仿函式。位計數透過 12 個算術操作(其中一個是乘法)實現。

cv::flann::DNAmmingLUT - 漢明距離仿函式在 DNA 比較中的改編。由於 DNA 的四個鹼基 A、C、G、T(或 RNA 的 A、G、C、U)可以用 2 位編碼,它使用查詢表實現來計算兩個序列之間的位對差異。

cv::flann::DNAmming2 - 漢明距離仿函式在 DNA 比較中的改編。由於使用標準暫存器的算術運算(AVX2 和 AVX-512 即將推出),鹼基差異計數已向量化。

cv::flann::HistIntersectionDistance - 直方圖交集距離仿函式。

cv::flann::HellingerDistance - 海林格距離仿函式。

cv::flann::ChiSquareDistance - 卡方距離仿函式。

cv::flann::KL_Divergence - Kullback-Leibler 散度仿函式。

儘管提供的實現涵蓋了廣泛的用例,也可以使用自定義實現。距離仿函式是一個類,其 operator() 計算兩個特徵之間的距離。如果該距離也是 kd-tree 相容距離,它還應提供一個 accum_dist() 方法,用於計算單個特徵維度之間的距離。

除了 operator()accum_dist() 之外,距離仿函式還應將 ElementTypeResultType 定義為其操作的元素的型別以及其計算結果的型別。如果距離仿函式可以用作 kd-tree 距離(這意味著一對特徵之間的完整距離可以從單個維度之間的部分距離累加),則距離仿函式內部應存在 typedef is_kdtree_distance。如果距離不是 kd-tree 距離,但它是向量空間中的距離(其操作的元素的單個維度可以獨立訪問),則仿函式內部應定義 typedef is_vector_space_distance。如果兩者都沒有定義,則假定該距離是度量距離,並且僅用於對通用度量距離進行操作的索引。

成員 Typedef 文件

◆ DistanceType

template<typename Distance >
Distance::ResultType cv::flann::GenericIndex< Distance >::DistanceType

◆ ElementType

template<typename Distance >
Distance::ElementType cv::flann::GenericIndex< Distance >::ElementType

建構函式 & 解構函式文件

◆ GenericIndex()

template<typename Distance >
cv::flann::GenericIndex< Distance >::GenericIndex ( const Mat & features,
const ::cvflann::IndexParams & params,
Distance distance = Distance() )

為給定資料集構造最近鄰搜尋索引。

引數
features包含待索引特徵(點)的矩陣。矩陣的大小為 num_features x feature_dimensionality,且矩陣中元素的資料型別必須與索引型別一致。
params包含索引引數的結構。將要構建的索引型別取決於此引數的型別。請參閱描述。
distance

該方法使用指定演算法和由 params 定義的引數,從一組特徵構造一個快速搜尋結構。params 是以下 IndexParams 類後代之一的引用:

  • LinearIndexParams 當傳遞此型別的物件時,索引將執行線性、暴力搜尋。
    struct LinearIndexParams : public IndexParams
    {
    };
  • KDTreeIndexParams 當傳遞此型別的物件時,構建的索引將由一組隨機 kd-tree 組成,這些 kd-tree 將並行搜尋。
    struct KDTreeIndexParams : public IndexParams
    {
    KDTreeIndexParams( int trees = 4 );
    };
  • HierarchicalClusteringIndexParams 當傳遞此型別的物件時,構建的索引將是一個分層聚類樹,將每組點分成 n 個聚類,其中心從點中選取,無需進一步細化其位置。該演算法適用於浮點、整數和二進位制向量。
    struct HierarchicalClusteringIndexParams : public IndexParams
    {
    HierarchicalClusteringIndexParams(
    int branching = 32,
    flann_centers_init_t centers_init = CENTERS_RANDOM,
    int trees = 4,
    int leaf_size = 100);
    };
  • KMeansIndexParams 當傳遞此型別的物件時,構建的索引將是一個分層 k 均值樹(預設為一棵樹),將每組點分成 n 個聚類,其重心迭代細化。請注意,當 knn 搜尋速度是標準時,此演算法已擴充套件以支援二進位制向量作為 LSH 的替代方案。在直接處理(即不使用 MCA/PCA)大多數維度點共享相同值的資料集時,它也將優於 LSH。建議對二進位制資料設定多於一棵樹。
    struct KMeansIndexParams : public IndexParams
    {
    KMeansIndexParams(
    int branching = 32,
    int iterations = 11,
    flann_centers_init_t centers_init = CENTERS_RANDOM,
    float cb_index = 0.2,
    int trees = 1);
    };
  • CompositeIndexParams 當使用此型別的引數物件時,建立的索引結合了隨機 kd-tree 和分層 k 均值樹。
    struct CompositeIndexParams : public IndexParams
    {
    CompositeIndexParams(
    int trees = 4,
    int branching = 32,
    int iterations = 11,
    flann_centers_init_t centers_init = CENTERS_RANDOM,
    float cb_index = 0.2 );
    };
  • LshIndexParams 當使用此型別的引數物件時,建立的索引使用多探測 LSH(引用自 Multi-Probe LSH: Efficient Indexing for High-Dimensional Similarity Search by Qin Lv, William Josephson, Zhe Wang, Moses Charikar, Kai Li., Proceedings of the 33rd International Conference on Very Large Data Bases (VLDB). Vienna, Austria. September 2007)。此演算法專為二進位制向量設計。
    struct LshIndexParams : public IndexParams
    {
    LshIndexParams(
    int table_number,
    int key_size,
    int multi_probe_level );
    };
  • AutotunedIndexParams 當傳遞此型別的物件時,建立的索引透過選擇最佳索引型別(隨機 kd-tree、分層 k 均值、線性)和所提供資料集的引數,自動調整以提供最佳效能。
    struct AutotunedIndexParams : public IndexParams
    {
    AutotunedIndexParams(
    float target_precision = 0.9,
    float build_weight = 0.01,
    float memory_weight = 0,
    float sample_fraction = 0.1 );
    };
  • SavedIndexParams 此物件型別用於從磁碟載入先前儲存的索引。
    struct SavedIndexParams : public IndexParams
    {
    SavedIndexParams( String filename );
    };
    std::string String
    定義 cvstd.hpp:151

◆ ~GenericIndex()

template<typename Distance >
cv::flann::GenericIndex< Distance >::~GenericIndex ( )

成員函式文件

◆ getIndexParameters()

template<typename Distance >
const ::cvflann::IndexParams * cv::flann::GenericIndex< Distance >::getIndexParameters ( )
inline

◆ getParameters()

template<typename Distance >
::cvflann::IndexParams cv::flann::GenericIndex< Distance >::getParameters ( )
inline

◆ knnSearch() [1/2]

template<typename Distance >
void cv::flann::GenericIndex< Distance >::knnSearch ( const Mat & 查詢,
Mat & 索引,
Mat & 距離,
int knn,
const ::cvflann::SearchParams & params )

◆ knnSearch() [2/2]

template<typename Distance >
void cv::flann::GenericIndex< Distance >::knnSearch ( const std::vector< ElementType > & query,
std::vector< int > & 索引,
std::vector< DistanceType > & 距離,
int knn,
const ::cvflann::SearchParams & params )

使用索引對給定查詢點執行 K-最近鄰搜尋。

引數
query查詢點
索引將包含找到的 K-最近鄰索引的向量。其大小必須至少為 knn。
距離將包含找到的 K-最近鄰距離的向量。其大小必須至少為 knn。
knn要搜尋的最近鄰數量。
paramsSearchParams

◆ radiusSearch() [1/2]

template<typename Distance >
int cv::flann::GenericIndex< Distance >::radiusSearch ( const Mat & query,
Mat & 索引,
Mat & 距離,
DistanceType radius,
const ::cvflann::SearchParams & params )

◆ radiusSearch() [2/2]

template<typename Distance >
int cv::flann::GenericIndex< Distance >::radiusSearch ( const std::vector< ElementType > & query,
std::vector< int > & 索引,
std::vector< DistanceType > & 距離,
DistanceType radius,
const ::cvflann::SearchParams & params )

使用索引對給定查詢點執行半徑最近鄰搜尋。

引數
query查詢點。
索引將包含找到的最近鄰索引的向量。
距離將包含找到的最近鄰距離的向量。其元素數量與索引相同。
radius搜尋半徑。
paramsSearchParams

此函式返回找到的最近鄰數量。

◆ save()

template<typename Distance >
void cv::flann::GenericIndex< Distance >::save ( String filename)
inline

◆ size()

template<typename Distance >
int cv::flann::GenericIndex< Distance >::size ( ) const
inline

◆ veclen()

template<typename Distance >
int cv::flann::GenericIndex< Distance >::veclen ( ) const
inline

此類的文件生成自以下檔案