<p>你似乎是<a href="http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html" rel="noreferrer">following this tutorial page</a>(基于你在本文中显示的代码和两个相关的问题<a href="https://stackoverflow.com/questions/31628505/matplotlib-importerror-cannot-import-name-pyplot#comment51209393_31628505">1</a>,<a href="https://stackoverflow.com/questions/31630559/attributeerror-module-object-has-no-attribute-orb">2</a>)。</p>
<p><a href="http://docs.opencv.org/3.0-beta/modules/features2d/doc/drawing_function_of_keypoints_and_matches.html#drawmatches" rel="noreferrer">function documentation is here</a>(尽管我注意到它仍然被标记为“beta”)并意味着<code>outImg</code>是可选的。但是,python错误消息是显式的-在位置6中需要一个参数,它在函数签名中被命名为<code>outImg</code>。我怀疑文档可能与代码要求不完全匹配。python绑定正在调用的<a href="https://github.com/Itseez/opencv/blob/master/modules/features2d/include/opencv2/features2d.hpp#L1111" rel="noreferrer">C++ code</a>的签名没有<code>outImg</code>的默认值,因此需要提供该参数。</p>
<p>注意,您可以通过查看<code><function_name>.__doc__</code>来检查python3解释器(如果存在的话)中的实际绑定的doc字符串。在这种情况下,可以看到<code>outImg</code>是<strong><em>而不是</em></strong>显示为可选的。以下是我的安装输出:</p>
<pre><code>>>> cv2.drawMatchesKnn.__doc__
'drawMatchesKnn(img1, keypoints1, img2, keypoints2, matches1to2, outImg[, matchC
olor[, singlePointColor[, matchesMask[, flags]]]]) -> outImg'
</code></pre>
<h3>解决方案(注意-已在windows安装而不是Linux上验证)</h3>
<p>您可能会注意到<a href="http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html#flann-based-matcher" rel="noreferrer">last example on that tutorial</a>,它使用以下代码传入<code>None</code>来代替<code>outImg</code>。我想这对你的案子也有用。</p>
<pre><code>draw_params = dict(matchColor = (0,255,0),
singlePointColor = (255,0,0),
matchesMask = matchesMask,
flags = 0)
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,matches,None,**draw_params)
</code></pre>
<p>你不需要通过所有的<code>draw_params</code>指令,你可以尝试通过<code>flags</code>即</p>
<pre><code>img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,matches,None,flags=2)
</code></pre>
<p>我已经在新安装的OpenCV 3上验证了这一点(尽管是在Windows上,使用预先构建的二进制文件)</p>