Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Python. K-nearest neighbour TypeError: samples data type = 17 is not supported

I'm trying to classify some images using SIFT for detect and compute keypoints and descriptors, and then use KNN for classify them into python interpreter:

## Detect keypoints and compute descriptors for train images
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

I really don't know how can fix this. Any help would be great. files is a list with 10 images, so the loop detects and computes keypoints and descriptor for each image. Thanks