我正在使用BOW旁边的ORB描述符训练SVM,但是当我执行它时,会收到以下错误消息
“返回bowDiction.compute(灰色,或orb.detect(灰色)) cv2.error:OpenCV(3.4.5)D:\ Build \ OpenCV \ opencv-3.4.5 \ modules \ features2d \ src \ matchers.cpp:753:错误:(-215:断言失败)_queryDescriptors.type()= =函数'cv :: BFMatcher :: knnMatchImpl'中的trainDescType'“
我了解的是,发生错误是因为查询描述符和训练描述符的类型不同,但是我找不到纠正它的方法。
for p in training_paths:
image = cv2.imread(p)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Initiate STAR detector
orb = cv2.ORB_create()
# find the keypoints with ORB
kp = orb.detect(gray,None)
# compute the descriptors with ORB
kp, des = orb.compute(gray, kp)
des = np.float32(des)
BOW.add(des)
#dictionary created
dictionary = BOW.cluster()
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks=50) # or pass empty dictionary
flann = cv2.FlannBasedMatcher(index_params,search_params)
orb2 = cv2.ORB_create()
bowDiction = cv2.BOWImgDescriptorExtractor(orb2, cv2.BFMatcher(cv2.NORM_L2))
bowDiction.setVocabulary(dictionary)
print("bow dictionary", np.shape(dictionary))
#returns descriptor of image at pth
def feature_extract(pth):
im = cv2.imread(pth, 1)
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
return bowDiction.compute(gray, orb.detect(gray))
train_desc = []
train_labels = []
i = 0
for p in training_paths:
##Error Here
train_desc.extend(feature_extract(p))
if names_path[i]=='Accordian':
train_labels.append(1)
if names_path[i]=='Dollar Bill':
train_labels.append(2)
if names_path[i]=='Motor Bike':
train_labels.append(3)
if names_path[i]=='Soccer Ball':
train_labels.append(4)
i = i+1
此后,我希望执行一些技术来评估SVM分类器的性能,我发现了划分和交叉验证的百分比,但是我不知道它们在这种情况下是否有效。
最后,我想知道在使用BOW训练SVM时应该考虑哪些方面。