dephinera
dephinera

Reputation: 3770

Opencv: Train SVM with FAST keypoints and BRIEF features

I want to train a SVM for object detection. At this point I have a python script which detects FAST keypoints and extracts BRIEF features at that location.

Now I don't know how to use these descriptors to train a SVM.

Would you tell me please:

  1. How to use the descriptors to train the SVM (As far as I know these descriptors should be my train data)?

  2. What are labels used for and how I can get them?

Upvotes: 3

Views: 2189

Answers (1)

elyase
elyase

Reputation: 40973

To train a SVM you would need a matrix X with your features and a vector y with your labels. It should look like this for 3 images and two features:

>>> from sklearn import svm
>>> X = [[0, 0],   <- negative 0
         [1, 3],   <- positive 1
          2, 5]]   <- negative 0
>>> y = [0,   
         1,
         0]
>>> model = svm.SVC()
>>> model.fit(X, y) 

The training set would consist of several images, each image would be a row of X and y.

Labels:

For the labels y you need positive and negative examples (0 or 1):

Positive Samples

You can specify positive samples in two ways. One way is to specify rectangular regions in a larger image. The regions contain the objects of interest. The other approach is to crop out the object of interest from the image and save it as a separate image. Then, you can specify the region to be the entire image. You can also generate more positive samples from existing ones by adding rotation or noise, or by varying brightness or contrast.

Negative Samples

Images that do not contain objects of interest.

[slightly edited from here]

Feature matrix X:

Here you can get creative but I will mention a simple idea. Make height * width features, one for each pixel of each image, but make them all 0 except in a small region around the FAST keypoints. In the end your X matrix will have dimension (n_images, height*width).

Another commonly used idea is Bag of Words. The X matrix must have a fixed number of features/columns and the number of keypoints is variable. This is a representation problem but it can be solved binning them in a histogram with a fixed number of bins. For details see for example this paper.

You will have to consult the specialized literature to come up with more ways to incorporate the BRIEF features but I hope this will give you an idea on how to get started.

Upvotes: 3

Related Questions