python - _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 时应该注意什么。
解决方案
推荐阅读
- angular - Angular mat-table 未显示数据,已修复,但不确定修复的原因
- javascript - 错误的(很可能)这个上下文
- r - 数据表中两列的常用条目
- sql - 设计问题:在 SQL 表中存储和检索增量的最佳方法
- kotlin - kotlin SQLite 数据库总是写默认值,从不写新值
- tensorflow - tfrecords 文件是否存在最佳元素数量?
- sql - 我无法打开 SQL Server 2014“无法连接到服务器”
- r - 匹配数据集中的值并重写以消除某些 II 类错误
- java - 每次点击时在 javafx 中更改电影院座位颜色
- go - 为什么我不能使用 net.go 的 conn.ok()?