我想在 Python 中使用基于 flann 的匹配器,如http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_feature2d/py_matcher/py_matcher.html中所述
由于我使用的是 OpenCV 3.0.0,我不得不调整有关 SIFT 检测器初始化的代码。其余部分保持不变
def calculateMatch(self):
# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
(kp1, desc1) = sift.detectAndCompute(self.image1,None)
(kp2, desc2) = sift.detectAndCompute(self.image2,None)
# FLANN parameters
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks=50) # or pass empty dictionary
flann = cv2.FlannBasedMatcher(index_params,search_params)
matches = flann.knnMatch(desc1,desc2,k=2)
当我运行代码时,我收到以下消息:
cv2.error: cv2.cpp:161: error: (-215) The data should normally be NULL! in function allocate
在行中:
matches = flann.knnMatch(desc1,desc2,k=2)
还有一条评论:如果我使用蛮力匹配器,一切正常:
bf = cv2.BFMatcher()
matches = bf.knnMatch(desc1, desc2, k=2)