What is .distance after doing a knnMatch?

What is .distance after doing a knnMatch?

本文关键字:knnMatch doing after is distance What      更新时间:2023-10-16

基本上我有:

BruteForceMatcher<L2<float>>().knnMatch(descriptor1,descriptor2,matches,2);

为了只获得良好的匹配,我解析了所有"匹配"向量并像这样检查距离:

if( (matches[i][0].distance / matches[i][1].distance) < ratio ){
  //> Good match!
}

但是matches[i][0].distance是什么意思?matches[i][0] 和 ? 之间的距离

我的假设

对于我能猜到的,对我来说,计算第一个匹配项与其 NN 之间的欧几里兰距离,并使用阈值对其进行过滤听起来更合乎逻辑,如下所示:

//> I calculate the distance between 2 nearest neighborhood and filter it based on thresold
foreach( matches : i) {
 if ( euclianDistance( matches[i][0] , matches[i][1] ) < threshold ) {
   //> good match
 }
}

描述符 - 是 N 维空间的一个点。

match - 是一对描述符 - 一个来自第一个集合,一个来自第二个集合(也称为训练集和查询集)。

距离 - 是match结构指向的 2 个描述符的L2度量。(您正在将指标类型指定为 BruteForceMatcher 的模板参数)。

match[i][0].distance = L2(descriptor1.row(match[i][0].trainIdx),
                          descriptor2.row(match[i][0].queryIdx))

因此,knnMatch训练集中的每个描述符返回查询集中两个最接近的描述符。接下来,您将过滤掉两个找到的描述符彼此接近的情况。