不绘制匹配项。 Opencv 3.0,完全更新了Ubuntu。代码运行但不显示任何匹配项。直接剪切测试区域并从图像中复制以匹配。
import numpy as np
import cv2
cv2.ocl.setUseOpenCL(False)
img1 = cv2.imread('images/ingrassroi.png',0)
img2 = cv2.imread('images/ingrass.png',0)
img3 = img1.copy()
# Initiate ORB detector
orb = cv2.ORB_create()
# compute the descriptors with ORB
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
# create BFMatcher object
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# Match descriptors.
matches = bf.match(des1,des2)
# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)
# Draw first 10 matches.
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None, flags=2)
cv2.imshow("Matches",img3)
cv2.waitKey(-1)
答案 0 :(得分:0)
原来,要匹配的图片太小了。它没有在火车图像中找到任何关键点。我从测试图像中放大了我裁剪的区域,它找到了匹配并正确识别出图像中的烟头。如果你决定在OpenCV Python教程的同一页面上尝试基于FLANN的匹配器,那么只需一个FYI,一定要定义FLANN_INDEX_LSH = 6.