OpenCV Python:没有drawMatchesknn函数

roh*_*ati 8 opencv python-2.7 flann

当我尝试使用本教程中提到的用于FLANN功能匹配的drawMatchesKnn函数时,我收到以下错误

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

我检查了其他资源,opencv中存在drawMatchesKnn方法.

为什么我收到此错误?

提前致谢

小智 5

这些功能cv2.drawMatchescv2.drawMatchesKnn在新版本的OpenCV 2.4中不可用。@rayryeng提供了一种轻量级的替代方案,该替代方案可用于的输出DescriptorMatcher.match。与的区别DescriptorMatcher.knnMatch在于,匹配项将作为列表列表返回。要使用@rayryeng替代项,必须将匹配项提取到一维列表中。

例如,可以对带有SIFT描述符蛮力匹配和比率测试教程进行如下修改:

# 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)
Run Code Online (Sandbox Code Playgroud)


mir*_*val 0

您需要使用 OpenCV 版本3。3.0.0-alphadrawMatchesKnn()中存在,但2.4.11中不存在

出现该错误是因为您使用的是旧版本的 OpenCV。