我有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
任何人都可以帮助我吗?
答案 0 :(得分:4)
注意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)