【问题标题】:Matching ORB descriptors, cant find good matches匹配 ORB 描述符,找不到好的匹配项
【发布时间】:2021-03-29 20:22:43
【问题描述】:

我正在尝试使用 ORB 匹配两个图像,使用蛮力匹配器导致随机匹配,应用 Low 的比率条件找不到任何正确的匹配!

我怀疑问题出在if m.distance < 0.7:我读到m.distance是从bf匹配器返回的两个discriptor之间的距离,但是值太大并且不符合条件,那么我该如何去除异常值呢?

我尝试过的:

  • 按距离排序列表matches = sorted(matches, key = lambda x:x.distance)
  • 使用 SIFT,效果很好!

排序对找到好的匹配没有帮助,而且SIFT是专利的,我想要ORB。

我的代码:

# finding feature points on products
image = productName + ".jpg"
path = "./images/products/"+image
img1 = cv2.imread(path,cv2.IMREAD_GRAYSCALE) 
orb = cv2.ORB_create()
kps1, des1 = orb.detectAndCompute(img1, None)
result=cv2.drawKeypoints(img1,kps1, img1,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS )
plt.figure(num=None, figsize=(20, 12), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(result)

# finding feature points on shelves
image = shelfName+'_raf.jpg'
path = "./images/shelves/"+image
img2 = cv2.imread(path,cv2.IMREAD_GRAYSCALE) 
orb = cv2.ORB_create()
kps2, des2 = orb.detectAndCompute(img2, None)
result=cv2.drawKeypoints(img2,kps2, img2,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
plt.figure(num=None, figsize=(20, 12), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(result)

bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=False)
matches = bf.match(des1, des2)

# store all the good matches as per Lowe's ratio test.
good = []
for m in matches:
    if m.distance < 0.7:
        good.append(m)
        
match_img = cv2.drawMatches(img1, kps1, img2, kps2, good, None, flags=2)

plt.figure(num=None, figsize=(20, 12), dpi=80, facecolor='w', edgecolor='k')
plt.imshow(match_img, 'gray')

如果我删除 Low 的条件,我会得到:

【问题讨论】:

  • 这不是劳氏比率检验。该代码至少在两个与此相关的地方存在严重错误。你从哪里得到这个代码?
  • 我从这个link得到它
  • 是的,这就是该问题中的代码 also 不起作用的原因。丢弃蛮力匹配器。您需要与 k=2 匹配的“knn”。否则无法进行劳氏比率检验。请阅读其他回复。或者从 OpenCV 中的示例目录中获取您的代码。
  • 圆圈代表什么?
  • 圆圈是特征点或关键点

标签: python opencv computer-vision


【解决方案1】:

代码尝试使用劳氏比率测试(参见原始 SIFT 论文)。

对于每个描述符,这需要 两个 最接近的匹配项。

代码应为:

matches = bf.knnMatch(desCam, desTrain, k=2) # knnMatch is crucial
good = []
for (m1, m2) in matches: # for every descriptor, take closest two matches
    if m1.distance < 0.7 * m2.distance: # best match has to be this much closer than second best
        good.append(m1)

此外,我强烈推荐 flann matcher。它比蛮力匹配器更快。

查看 OpenCV tutorials 或 OpenCV 源代码 (samples/python/find_obj.py) 中的示例目录以获取有效的代码。

【讨论】:

  • 谢谢克里斯托夫,你的回答很有效,而且我还必须将第一张和第二张图像的关键点数量更改为 10,000 和 100,000。
猜你喜欢
  • 1970-01-01
  • 2017-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
  • 2015-12-24
相关资源
最近更新 更多