踩坑opencv3.4官方例子量图片匹配img3 = cv.drawMatches(img1,kp1,img2,kp2,matches[:10], flags=2),
第六个函数outimg官方没有,很多书也是复制粘贴并没有实际操作会报错TypeError: Required argument 'outImg' (pos 6) not found
亲测成功img2 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None,flags=2)需将outImg加上None。本人下3.4.3官方例子错误。
import cv2 import numpy as np from matplotlib import pyplot as plt img1 = cv2.imread('box.png',0) # queryImage img2 = cv2.imread('box_in_scene.png',0) # trainImage cv2.imshow("im1",img1) cv2.imshow("im2",img2) orb = cv2.ORB_create() kp1, des1 = orb.detectAndCompute(img1,None) kp2, des2 = orb.detectAndCompute(img2,None) bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) matches = bf.match(des1,des2) matches = sorted(matches, key = lambda x:x.distance) img2 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None,flags=2) plt.imshow(img2),plt.show() cv2.waitKey(0) cv2.destroyAllWindows()