且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TypeError:找不到必需的参数"outImg"(位置6)

更新时间:2022-05-24 22:36:10

您似乎是 1

You seem to be following this tutorial page (based on the code you've shown in this and your two related questions 1, 2).

功能文档在这里(尽管我注意到它仍被标记为"beta"),并表示outImg是可选的.但是,python错误消息是显式的-位置6处需要一个参数,在函数签名中将其命名为outImg.我怀疑文档可能与代码要求不完全匹配. 出现 :

The function documentation is here (although I note it is still labelled "beta") and implies that outImg is optional. However, the python error message is explicit - an argument is required in position 6, it is named outImg in the function signature. I suspect the documentation may not exactly match the code requirements. It appears that the signature of the C++ code that the python binding is calling has no default value for outImg, so need that argument to be supplied.

请注意,您可以通过查看<function_name>.__doc__来检查doc字符串中python3解释器中的实际绑定(如果存在).在这种情况下,您可以看到outImg not (可选).这是我安装的输出:

Note that you can inspect the doc string for the actual binding in the python3 interpreter (if it exists) by looking at <function_name>.__doc__. In this case, you can see that outImg is not shown as optional. Here is the output from my installation:

>>> cv2.drawMatchesKnn.__doc__
'drawMatchesKnn(img1, keypoints1, img2, keypoints2, matches1to2, outImg[, matchC
olor[, singlePointColor[, matchesMask[, flags]]]]) -> outImg'

解决方案(注意-在Windows安装而不是Linux上验证)

您可能会注意到该教程的最后一个示例,它使用以下代码-将None替换为outImg.我认为这也适用于您的情况.

Solution (note - verified on a windows install, not Linux)

You might note the last example on that tutorial, which uses the following code - passing in None in the place of outImg. I think that will work for your case also.

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)

您不需要传递所有draw_params格,您可以尝试仅传递flags即.

You don't need to pass all the draw_params dict, you could try just passing flags i.e.

img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,matches,None,flags=2)

我已经在全新安装的OpenCV 3(尽管在Windows中使用预构建的二进制文件)上对此进行了验证

I have verified this on a fresh install of OpenCV 3 (albeit on Windows, using a prebuilt binary)