opencv+flann库+GenericIndex类

本文介绍如何使用OpenCV中的FLANN模块构建高效最近邻搜索索引。包括多种索引类型如线性搜索、kd树、层次k-means树等,并详细解释了各类型索引参数设置的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

template<typename Distance >

cv::flann::GenericIndex< Distance >::GenericIndex(const Mat & features,


const ::cvflann::IndexParams & params,


Distance distance = Distance() 
 )

类的作用:根据给定数据集构建最近邻搜索索引

参数:

features 包含特征(点)的矩阵,用于索引。矩阵的大小等于num_feature(特征数)× feature_dimensionality(特征维数)(原文:The size of the matrix is num_features x feature_dimensionality) 矩阵元素的数据类型必须和索引类型相同。

params  包含索引参数的结构体(原文:Structure containing the index parameters)索引的类型将取决于该参数的类型。

distance 该方法使用具有指定参数的指定算法从一组特征构造快速搜索结构,如params所定义。

 params是对以下类IndexParams后代之一的引用:

  • LinearIndexParams When passing an object of this type, the index will perform a linear, brute-force search. :
    struct LinearIndexParams : public IndexParams
    {
    };
  • KDTreeIndexParams When passing an object of this type the index constructed will consist of a set of randomized kd-trees which will be searched in parallel. :
    struct KDTreeIndexParams : public IndexParams
    {
    KDTreeIndexParams( int trees = 4 );
    };
  • KMeansIndexParams When passing an object of this type the index constructed will be a hierarchical k-means tree. :
    struct KMeansIndexParams : public IndexParams
    {
    KMeansIndexParams(
    int branching = 32,
    int iterations = 11,
    float cb_index = 0.2 );
    };
  • CompositeIndexParams When using a parameters object of this type the index created combines the randomized kd-trees and the hierarchical k-means tree. :
    struct CompositeIndexParams : public IndexParams
    {
    CompositeIndexParams(
    int trees = 4,
    int branching = 32,
    int iterations = 11,
    float cb_index = 0.2 );
    };
  • LshIndexParams When using a parameters object of this type the index created uses multi-probe LSH (by 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(
    unsigned int table_number,
    unsigned int key_size,
    unsigned int multi_probe_level );
    };
  • AutotunedIndexParams When passing an object of this type the index created is automatically tuned to offer the best performance, by choosing the optimal index type (randomized kd-trees, hierarchical kmeans, linear) and parameters for the dataset provided. :
    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 This object type is used for loading a previously saved index from the disk. :
    struct SavedIndexParams : public IndexParams
    {
    SavedIndexParams( String filename );
    };
参数介绍可以看这篇文章:https://blog.youkuaiyun.com/app_12062011/article/details/51987352
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值