如何找到两个描述之间的距离

How to find the distance between the two discriptos?

本文关键字:描述 两个 之间 距离 何找      更新时间:2023-10-16

我在yml文件中有一个来自一组图像的词汇表(簇的质心)。现在我已经从一个图像中获得了一个新的SURF描述符。现在,我想用一些阈值来检查这个新的关键点描述符与词汇表的距离,并保存好的和坏的匹配。一旦我有了好的和坏的描述,我怎么能在图像上把它们标记为关键点。我对opencv很陌生。我已经看过knnMatch,但它只通过指定k来提供良好的匹配。有人能通过建议或示例代码帮助我吗。

这是我的样本代码

  Mat dictionary;
  FileStorage fs("../bin/dictionary1.yml", FileStorage::READ);
  fs["vocabulary"] >> dictionary;
  fs.release();
  std::vector<KeyPoint> keypoints_1;
  detector.detect( img_1, keypoints_1 );
  SurfDescriptorExtractor surfDesc;
  Mat descriptors1;
  surfDesc.compute(img_1, keypoints_1, descriptors1);

我想做一些事情,比如这个

for all image descriptor
 for all vacabulary
   if(dist is less)
     goodmatch
     cvcolor=blue
   else 
     badmatch
     cvcolor=red

您可以使用欧氏距离d=sqrt(a1^2+a2^2+…an^2),但在这种情况下,最好使用Mahalanobis距离,因为它考虑了分布参数(协方差)。但你需要计算每个集群的协方差,这可以在训练阶段得到。你有集群的中心,每个集群都有点,足以进行协方差评估。

相关文章: