OpenCV Python:没有drawMatchesknn函数

时间:2013-11-24 09:20:25

标签: opencv python-2.7 flann

当我尝试使用此tutorial中提到的drawMatchesKnn函数进行FLANN功能匹配时,出现以下错误

  

AttributeError:'module'对象没有属性'drawMatchesKnn'

我使用其他资源检查了opencv中是否存在drawMatchesKnn方法。

为什么我收到此错误?

提前致谢

3 个答案:

答案 0 :(得分:5)

在较新版本的OpenCV 2.4中,函数cv2.drawMatchescv2.drawMatchesKnn不可用。 @rayryeng提供了lightweight alternative,其作用与DescriptorMatcher.match的输出相同。与DescriptorMatcher.knnMatch的区别在于匹配作为列表列表返回。要使用@rayryeng替代方案,必须将匹配提取到1-D列表中。

例如,Brute-Force Matching with SIFT Descriptors and Ratio Test教程可以修改为:

# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)

# Apply ratio test
good = []
for m,n in matches:
    if m.distance < 0.75*n.distance:
       # Removed the brackets around m 
       good.append(m)

# Invoke @rayryeng's drawMatches alternative, note it requires grayscale images
gray1 = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
gray2 = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
drawMatches(gray1,kp1,gray2,kp2,good)

答案 1 :(得分:0)

您需要使用OpenCV版本3. 3.0.0-alpha中存在drawMatchesKnn()2.4.11中不存在{{1}}

该错误存在,因为您使用的是旧版本的OpenCV。

答案 2 :(得分:-1)

与其做good.append(m),不如试试good.append([m])