当我运行我的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。
cv2.drawMatches(img1, keypoints1, img2, keypoints2, matches1to2[, outImg[, matchColor[, singlePointColor[, matchesMask[, flags]]]]])
,因此我推测如果您指定了flags
,则需要同时指定所有先前的参数。 - Pynchiacv2.BFMatcher_create()
已经取代了默认的cv2.BFMatcher()
,根据官方文档。 - Zhanwen Chen