import cv2
import numpy as np
MIN_MATCH_COUNT = 30
#Initiate Sift detector for brute force matching
detector = cv2.xfeatures2d.SIFT_create()
#FLANN Parameters(finds nearest neighbors)
FLANN_INDEX_KDITREE=0
flannParam = dict(algorithm = FLANN_INDEX_KDITREE, tree=5)
flann = cv2.FlannBasedMatcher(flannParam, {})
#Initialize train image
img1 = cv2.imread("2.jpg")
img2 = cv2.imread("1.jpg")
trainImg = [img1,img2]
trainKP, trainDesc = detector.detectAndCompute(trainImg,None)
如何将多个图片提供给detectAndCompute()
方法?
将此视为错误:
trainKP,trainDesc = detector.detectAndCompute(trainImg,None)
TypeError:image不是numpy数组,也不是标量
答案 0 :(得分:0)
似乎你无法将图像列表传递给detectAndCompute。它需要像这样使用
kp1, des1 = detector.detectAndCompute(img1,None)
kp2, des2 = detector.detectAndCompute(img1,None)
或使用for循环
trainImg = [img1,img2]
for img in trainImg:
kp, desc = detector.detectAndCompute(img, None)
# Process kp and desc
此外,如果你正在寻找一个教程,这是一个非常好的用于python中的基本功能匹配 http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_matcher/py_matcher.html