Fast Library forApproximate Nearest Neighbors
1.创建对象
<FlannBasedMatcher object> = cv.FlannBasedMatcher( [, indexParams[, searchParams]] )
indexParams
参数 | 描述 |
---|---|
FLANN_INDEX_LINEAR | 线性暴力(brute-force)搜索 |
FLANN_INDEX_KDTREE | 随机kd树,平行搜索。默认trees=4 |
FLANN_INDEX_KMEANS | 层次k均值树。默认branching=32,iterations=11,centers_init = CENTERS_RANDOM, cb_index =0.2 |
FLANN_INDEX_COMPOSITE | 随机kd树和层次k均值树来构建索引。默认trees =4,branching =32,iterations =11,centers_init = CENTERS_RANDOM,cb_index =0.2 |
FLANN_INDEX_KDTREE_SINGLE | |
FLANN_INDEX_HIERARCHICAL | |
FLANN_INDEX_LSH | multi-probe LSH方法 |
FLANN_INDEX_SAVED | |
FLANN_INDEX_AUTOTUNED | |
LINEAR | |
KDTREE | |
KMEANS | |
COMPOSITE | |
KDTREE_SINGLE | |
SAVED | |
AUTOTUNED | 自动选取,以提供最好的性能 |
searchParams
SearchParams (int checks=32, float eps=0, bool sorted=true)
参数 | 描述 |
---|---|
checks | 默认32 |
eps | 默认为0 |
sorted | 默认True |
2.匹配方法
FlannBasedMatcher对象继承了cv::DescriptorMatcher.
matches = cv.DescriptorMatcher.knnMatch( queryDescriptors, trainDescriptors, k[, mask[, compactResult]] )
matches = cv.DescriptorMatcher.knnMatch( queryDescriptors, k[, masks[, compactResult]] )
参数 | 描述 |
---|---|
queryDescriptors | 原图 |
trainDescriptors | 搜索的图片 |
matches | 匹配的结果 |
k | Count of best matches found per each query descriptor or less if a query descriptor has less than k possible matches in total.设置阈值,越高精度越高,匹配的数量越少 |
masks | Set of masks. |
compactResult | Parameter used when the mask (or masks) is not empty. |
matches
参数 | 描述 |
---|---|
distance | |
imgIdx | 训练图片的索引 |
queryIdx | query descriptor index |
trainIdx | train descriptor index |
参考文献:
https://www.jianshu.com/p/d70d9c8b2bec
https://docs.opencv.org/3.4.3/d5/d03/structcv_1_1flann_1_1SearchParams.html
https://docs.opencv.org/3.4.3/dc/d8c/namespacecvflann.html#a4e3e6c98d774ea77fd7f0045c9bc7817af67e191e4866496ff7db55c24277f4a4
https://docs.opencv.org/master/db/d39/classcv_1_1DescriptorMatcher.html#a38f18a66b3498fa5c960e29ed0056d44