OpenCV Python:没有drawMatchesknn函数 [英] OpenCV Python : No drawMatchesknn function
问题描述
When I tried to use drawMatchesKnn function as mentioned in this tutorial for FLANN feature matching, I get the following error
AttributeError:模块"对象没有属性"drawMatchesKnn"
AttributeError: 'module' object has no attribute 'drawMatchesKnn'
我与其他资源一起检查了opencv中是否存在drawMatchesKnn方法.
I checked with other resources that drawMatchesKnn method is present in opencv.
为什么会出现此错误?
预先感谢
推荐答案
功能cv2.drawMatches
和cv2.drawMatchesKnn
在较新版本的OpenCV 2.4中不可用. @rayryeng提供了一个轻量级替代,它可以与DescriptorMatcher.match
的输出一样使用.与DescriptorMatcher.knnMatch
的区别在于,匹配项以列表列表的形式返回.要使用@rayryeng替代项,必须将匹配项提取到一维列表中.
The functions cv2.drawMatches
and cv2.drawMatchesKnn
are not available in newer versions of OpenCV 2.4. @rayryeng provided a lightweight alternative which works as is for the output of DescriptorMatcher.match
. The difference with DescriptorMatcher.knnMatch
is that the matches are returned as a list of lists. To use the @rayryeng alternative, the matches must be extracted into a 1-D list.
例如,与SIFT描述符和比率测试的蛮力匹配教程可以作如下修改:
For example, the Brute-Force Matching with SIFT Descriptors and Ratio Test tutorial could be amended as such:
# 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)
这篇关于OpenCV Python:没有drawMatchesknn函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!