如何对opencv flann(knnsearch)实施余弦度量

How to implement Cosine Metric to opencv flann (knnsearch)

我正在使用 opencv flann 索引在数据库中搜索图像。 正如我在文档中看到的那样,flann 提供如下指标:

   FLANN_DIST_EUCLIDEAN = 1,
    FLANN_DIST_L2 = 1,
    FLANN_DIST_MANHATTAN = 2,
    FLANN_DIST_L1 = 2,
    FLANN_DIST_MINKOWSKI = 3,
    FLANN_DIST_MAX   = 4,
    FLANN_DIST_HIST_INTERSECT   = 5,
    FLANN_DIST_HELLINGER = 6,
    FLANN_DIST_CHI_SQUARE = 7,
    FLANN_DIST_CS         = 7,
    FLANN_DIST_KULLBACK_LEIBLER  = 8,
    FLANN_DIST_KL                = 8,
    FLANN_DIST_HAMMING          = 9,

没有余弦距离 那么,如何将其实现到opencv lib中呢? 谢谢

这是几年前在 flann github 仓库中出现的。 (请参阅 this issue。)要点(据我了解)是余弦相似度不是距离度量。问题中有更深入的解释。