【问题标题】:OpenCV SIFT+FLANN multiple matches for single keypointOpenCV SIFT+FLANN 多个匹配单个关键点
【发布时间】:2022-06-18 03:48:34
【问题描述】:

我正在尝试使用 open cv 匹配关键点。 具体来说,我使用的是“sift”检测器和“flann”匹配器。我的代码基于cv2's documentation:

detector = cv2.SIFT_create()
matcher = cv2.FlannBasedMatcher(indexParams=dict(algorithm=0, trees=5), searchParams=dict(checks=50))
kps1, desc1 = detector.detectAndCompute(img1, None)
kps2, desc2 = detector.detectAndCompute(img2, None)
all_matches = matcher.knnMatch(desc1, desc2, 2)

ratio = 0.7
good_matches = []
for m, n in all_matches:
  if m.distance <= ratio * n.distance:
    good_matches.append(m)

我注意到,即使在 good_matches 列表中,我也有一些关键点有多个匹配项:

extra_matches = dict()
for match in good_matches:
  t_idx = match.trainIdx
  reps = [mch for mch in good_matches if mch.trainIdx == t_idx]
  if len(reps) > 1 and t_idx not in extra_matches.dict():
    extra_matches[t_idx] = reps

print(len(extra_matches))  # not 0

我觉得这很奇怪,因为我认为 knnMatch 已经产生了 2 个最佳匹配项。为什么在对匹配进行比率修剪后,每个关键点会有多个匹配?

【问题讨论】:

    标签: python opencv keypoint


    【解决方案1】:

    果然,发帖五分钟后我找到了答案:

    FLANN 不进行交叉检查,这意味着我将重复第二个关键点,但没有重复第一个关键点(也在我的代码中验证)。 如果您需要与FLANN 进行交叉检查,最佳做法是实现自己的交叉检查或使用FLANN 获取描述符子集,然后使用BFMatcher 的交叉检查选项。

    以下是其他一些信息来源:[1][2]

    【讨论】:

      【解决方案2】:

      你能详细说明你的答案吗?我不知道如何从你的描述着手。请您提供更多详细信息吗?

      【讨论】:

        猜你喜欢
        • 2018-09-12
        • 2015-03-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-02
        • 2014-09-17
        • 1970-01-01
        相关资源
        最近更新 更多