首页 > 解决方案 > _queryDescriptors.type() == trainDescType 使用 BoW of ORB 特征训练 SVM 错误

问题描述

我正在使用 BOW 旁边的 ORB 描述符训练 SVM,但是当我执行它时,我收到以下错误

"返回 bowDiction.compute(gray, orb.detect(gray)) 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 时应该注意什么。

标签: pythonimage-processingsvmtraining-dataorb

解决方案


推荐阅读