【发布时间】: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')
【问题讨论】:
-
这不是劳氏比率检验。该代码至少在两个与此相关的地方存在严重错误。你从哪里得到这个代码?
-
我从这个link得到它
-
是的,这就是该问题中的代码 also 不起作用的原因。丢弃蛮力匹配器。您需要与 k=2 匹配的“knn”。否则无法进行劳氏比率检验。请阅读其他回复。或者从 OpenCV 中的示例目录中获取您的代码。
-
圆圈代表什么?
-
圆圈是特征点或关键点
标签: python opencv computer-vision