0
votes

I've been trying to use SURF features to make a classifier with sklearn SVM (to identify one class of objects). I keep running into problems with the dimensions of the feature vectors. I've generated an array of feature objects and an array of descriptors but what do I use as the feature vector? I tried passing the features and descriptors directly as parameters as follows:

sd = cv2.FeatureDetector_create("SURF")
keypoints = sd.detect(img)
kp,des = surf.compute(img, keypoints)
model = svm.SVC()
model.fit(des,['type1'])

Do I have to extract the attributes of the features objects or the descriptor array to get the final feature vector? What should be the dimension of the feature vector? Shouldn't it be an array of vectors (one vector for a keypoint)?

1
Why not try whatever you can and see what works? I would probably start with the array of keypoints.Ashalynd
Well, I tried putting the angle, and coordinates of the features of the points in a list of vectors, but its seems that I require one label per vector. I get an error saying "X and y have incompatible shapes". My question is: Why should we have one label per vector? Shouldn't we have one label for a list of vectors (As the entire list of vectors represents one image)?PrithviJC
Every vector being fed into an SVM is a separate training item. So everything you know about the image that's relevant needs to go into one vector. You then need to give it a lot of vectors, that represent a lot of images. I think you've got some fundamental misconceptions about image features, and SVM features, and that's the cause of your present confusion.Jay Kominek
You're right. I was trying to somehow relate the image features for one single keypoint to TF/IDF used for a whole document in NLP and just got thoroughly confused. Got it straight now though.PrithviJC

1 Answers

0
votes

I solved it. The problem was to "flatten" the multi dimension descriptor to a single dimension vector that describes the entire set of keypoints. I resized the image to a standard number of rows and columns and flattened out the 2D grid of pixels to a single dimension array. Every element in the array uniquely identifies one pixel and takes values 1 or 0 (1 means it is a keypoint). I can extend the array with a similar format if I want to add more descriptive features per keypoint (the value of the array element in the extension will be the value of the descriptive feature). This makes one single dimension vector containing the required feature information for the whole image.