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

Shi*_*Tio 1 python opencv numpy python-3.x orb

我有以下 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()
Run Code Online (Sandbox Code Playgroud)

我运行后出现以下错误:

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

任何人都可以帮助我吗?

Kin*_*t 金 6

注意 的原型cv2.drawMatches()

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

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


来自

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

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