Search code examples
opencvneural-networkfeature-detectionobject-detectionsurf

Using Bag of words/features and neural network


I'm trying to implement an object detection module which contains the following steps:

1) extract image descriptors with SURF, creating a matrix of size [x, 64], where x depends of the number of keypoints found in the image;

2) fix the descriptor size to a [k,64] format using bag of features/words approach. Where k is the number of clusters created using k-means.

3) feed a neural network using the resulting bag of words matrix as trainingSamples.

So far I've implemented steps 1 and 2 but I'm not quite sure how to format the output vector of the NN. On OpenCV CvANN_MLP, the number of rows in the output vector should have the same number of the input rows (otherwise returns an what() exception), but the number of input rows are the number of the k clusters on step 2, so I'm not understanding how to write the output matrix based on that.

I know the output matrix should have n columns corresponding to the number of classes in the output that I want (e.g. 3 classes: cat, dog and bird will result on a matrix with 3 columns), but how do I organize the rows of this matrix based on the input rows? I read this related post , it uses matlab and it says that each feature should be a row, but I'm not sure how to do this on OpenCV C++. If anyone has any idea/tips of how to proceed with that, it would be very appreciated.


Solution

  • Have you done this:

    However, before you train your neural network, as you suspected, you must represent every image you wish to train with this feature vector.

    Before feeding your neural network? I lack in experience in using neural networks, however after reading this and your question, it seems that you are trying to feed the bag-of-words clusters to your neural network, which is incorrect.