使用"cv2.drawMatches"时,出现错误:"outImg is not a numpy array, neither a scalar"

When use "cv2.drawMatches", error occurs: "outImg is not a numpy array, neither a scalar"

我有以下用于 ORB 关键帧匹配的代码:

import numpy as np
import cv2
from matplotlib import pyplot as plt

img1 = cv2.imread("C:\Users\user\Desktop\picture\Pikachu_Libre.png",0)
img2 = cv2.imread("C:\Users\user\Desktop\picture\Pikachu_Libre.png",0)
# Initiate STAR detector
orb = cv2.ORB_create()

# find the keypoints with ORB
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
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,None,matches[:10], flags=2)
plt.imshow(img3),plt.show()

在我 运行 之后,我得到以下错误:

img3 = cv2.drawMatches(img1,kp1,img2,kp2,None,matches[:10], flags=2)
TypeError: outImg is not a numpy array, neither a scalar

谁能帮我解决这个问题?

注意cv2.drawMatches()的原型:

cv2.drawMatches(img1, keypoints1, img2, keypoints2, matches1to2, outImg[, matchColor[, singlePointColor[, matchesMask[, flags]]]]) -> outImg

所以你的参数顺序是错误的。


发件人:

img3 = cv2.drawMatches(img1,kp1,img2,kp2,None,matches[:10], flags=2)

:

img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10], None,flags=2)