当我运行我的python代码时
import numpy as np
import cv2
import matplotlib.pyplot as plt
img1 = cv2.imread('/home/shar/home.jpg',0) # queryImage
img2 = cv2.imread('/home/shar/home2.jpg',0) # trainImage
# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)
kp2, des2 = sift.detectAndCompute(img2,None)
# 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:
good.append([m])
# cv2.drawMatchesKnn expects list of lists as matches.
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2)
plt.imshow(img3),plt.show()
从这一行
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2)
我收到此错误
TypeError: Required argument 'outImg' (pos 6) not found
我正在使用python3和opencv3
答案 0 :(得分:61)
您似乎是following this tutorial page(根据您在此处显示的代码以及您的两个相关问题1,2)。
function documentation is here(虽然我注意到它仍标记为“beta”),并暗示outImg
是可选的。但是,python错误消息是显式的 - 在位置6中需要一个参数,它在函数签名中被命名为outImg
。我怀疑文档可能与代码要求不完全一致。 出现 ,python绑定调用的C++ code的签名没有outImg
的默认值,因此需要提供该参数
请注意,您可以通过查看<function_name>.__doc__
来检查文档字符串中python3解释器中的实际绑定(如果存在)。在这种情况下,您可以看到outImg
不 显示为可选。这是我的安装输出:
>>> cv2.drawMatchesKnn.__doc__
'drawMatchesKnn(img1, keypoints1, img2, keypoints2, matches1to2, outImg[, matchC
olor[, singlePointColor[, matchesMask[, flags]]]]) -> outImg'
您可能会注意到使用以下代码的last example on that tutorial - 在None
代替outImg
。我认为这也适合你的情况。
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
,即。
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,matches,None,flags=2)
我已经在全新安装的OpenCV 3上验证了这一点(虽然在Windows上,使用预建的二进制文件)
答案 1 :(得分:15)
好的伙计们,我是一名新手并且经过数小时的在线研究后学到了很多关于错误的错误(-255)NumpyAllocator,许多网站会建议你打开cv2.cpp文件并发表评论出了163行代码,我的建议是如果你使用OpenCV 3.1下载等级到OpenCV 3.0.0
这个bug似乎在OpenCV 3.1中,除此之外,在OpenCV.org上记录的使用ORB算法的代码有点过时了
在哪里陈述
enter code here
#启动ORB检测器
enter code here
orb = cv2.ORB()#note注意您将收到错误,因为现在enter code here
已更改为:
enter code here
orb = cv2.ORB_create()
以下是我在Windows 10上使用OpenCV 3.0.0的代码示例:
# Example of Brute Force matching base on ORB Algorithm
#Modify Author : Waheed Rafiq R&D student Birmingham City University UK
#Original author : OpenCV.org
#Date Updated : 21/04/2016 : 13:45
import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('wr-pb.jpg',0) # queryImage
img2 = cv2.imread('Waheed.jpg',0) # trainImage
# Initiate ORB detector
orb = cv2.ORB_create()
# find the keypoints and descriptors with ORB
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
# create BFMatcher object
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# Match descriptors.
matches = bf.match(des1,des2)
# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)
# Draw first 10 matches.
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches ,None, flags=2)
plt.imshow(img3),plt.show()
我希望这会有所帮助,我喜欢堆栈Over flow是互联网上最好的资源。
答案 2 :(得分:1)
我的代码:img3 = cv2.drawMatchesKnn(img1, kp1, img2, kp2, good, flags=2)
在此代码,关键字和参数=“ None”之后进行工作:img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches ,None, flags=2)
答案 3 :(得分:-1)
这可能是一个错误。你可以做的是你可以将第6个参数传递为//Define schema of file, must map all columns
@searchlog =
EXTRACT UserId int,
Start DateTime,
Region string,
Query string,
Duration int,
Urls string,
ClickedUrls string
FROM @"/Samples/Data/SearchLog.tsv"
USING Extractors.Tsv();
OUTPUT @searchlog
TO @"/Samples/Output/SearchLog_output.tsv"
USING Outputters.Tsv();
。
//Define schema of file, must map all columns
@searchlog =
EXTRACT ID1 int,
ID2 int,
Date DateTime,
Rs string,
Rs1 string,
Number string,
Direction string,
ID3 int
FROM @"adl://rdl1.azuredatalakestore.net/blob1/vehicle1_09142014_JR.csv"
USING Extractors.Csv();
OUTPUT @searchlog
TO @"adl://rdl1.azuredatalakestore.net/blob1/vehicle1_09142014_JR1.csv"
USING Outputters.Csv();
experimenting with SIFT时我遇到了类似的问题。当我使用None
作为参数时,我能够解决它。