I'm trying to classify some images using SIFT for detect and compute keypoints and descriptors, and then use KNN for classify them:
This is my little code:
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)
But I'm a little stuck with the next error
>>> 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
files is a list with 10 images, so the loop detects and computes keypoints and descriptor for each image. I give you some images.Thanks


