我想使用一些圖像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