I'm trying to retrieve a set of similar images based on an input image. I'm using setting an array element with a sequence. setting an array element with a sequence. OpenCV
for Python
by the way. My strategy is that I get the SURF
features of the database of images and then I put it into the k-NN
model so that whenever I query an image by using the SURF Features and look for the similar set of items, I can just use k-NN
to get the nearest neighbors. The problem is, I tried training the k-NN
model in scikit-learn
by putting the SURF
descriptors and then flattening it. However, this error keeps on showing up whenever I try train the model. setting an array element with a sequence.setting an array element with a sequence.
What am I doing wrong? How should I represent the features so that I can use it with k-NN
UPDATE: Here's my code
SURFObject = cv2.SURF(hessianThreshold = 400, extended = 0)
image_names = []
image_descriptors = []
for i in range(1, 4001):
print("Image Number: " + str(i))
filename = 'cat.'+ str(i) +'.jpg'
img = cv2.imread(filepath + filename)
keypoints, descriptors = SURFObject.detectAndCompute(img, None)
image_descriptors.append(descriptors.tolist())
image_names.append(filename)
neighbors = NearestNeighbors(10, 0.5)
neighbors.fit(np.array(image_descriptors).reshape(-1,1))