我想使用一些图像SIFT的检测和计算关键点和描述符,然后用KNN分类为它们进行分类:Python。 K近邻类型错误:样本数据类型= 17不支持
这是我的小码:
import os
import cv2
## Prepare images files
rootpath = '/Some/Directory'
files = []
for filedir, dirs, filess in os.walk(rootpath):
for filename in filess:
pathfile = os.path.join(filedir, filename)
files.append(pathfile)
## Detect keypoints and compute descriptors for train images
kp_train = []
dsc_train = []
for file in files:
ima = cv2.imread(file)
gray=cv2.cvtColor(ima,cv2.COLOR_BGR2GRAY)
kpts, des = sift.detectAndCompute(gray, None)
kp_train.append(kpts)
dsc_train.append(des)
## Train knn
dsc_train = np.array(dsc_train)
responses = np.arange(len(kp_train),dtype = np.float32)
knn = cv2.ml.KNearest_create()
knn.train(dsc_train, cv2.ml.ROW_SAMPLE, responses)
但我有点卡住下一个错误
>>> knn.train(dsc_train,cv2.ml.ROW_SAMPLE,responses)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: dsc_train data type = 17 is not supported
文件是用10张名单,因此该循环检测并计算柯每个图像的y点和描述符。我给你一些images.Thanks
你可以包含缩减的样本日期集来证明,maby三张图片吗? – tfv
如果代码完整(包括导入语句,文件名等)和可用的数据以便我们可以复制它,您可能会得到更快的响应。 – tfv
@tfv我编辑了这篇文章。核实。感谢您的建议 – Jose