Training of SVM classifier in OpenCV using SIFT and ORB features

user1699901 picture user1699901 · Sep 26, 2012 · Viewed 9.4k times · Source

I'm trying to train a SVM classifier to recognize pedestrians in a set of 64x128 images. I've already done that using HOG features, and now I need to implement the same thing using SIFT and ORB. For HOG features, I had always the same number of features (3780), so that the matrix for the train was image_number by 3780. Now, using SIFT extractor I get keypoints of different sizes. How can I create a matrix for the classifier using these keypoints of different sizes?

Many thanks for your help!

I solved the descriptors' issue putting all of them in the same row. However, I found out that most of desriptors have a 0 value, so the classifier doesn't work well. Do you know how can I solve this problem?

This is a piece of the code:

DenseFeatureDetector detector;
SiftDescriptorExtractor descriptor;
vector<KeyPoint> keypoints;


//for every image I compute te SIFT
detector.detect(image, keypoints);
Mat desc;
descriptor.compute(image,keypoints, desc);
Mat v(1,30976,CV_32FC1);
    for (int j = 0; j<desc.rows; j++){
        for(int k = 0; k<desc.cols; k++){
            v.at<float>(0,128*j+k) = desc.at<float>(j,k);

        }
    } //now in vector v there are all the descriptors (the problem is that most of them have 0 value)

descriptormat.push_back(v);  //descriptormat is the cv::Mat that I use to train the SVM

Answer

user334856 picture user334856 · Oct 4, 2012

Usually, people vector-quantize SIFT or ORB features and build histograms (bags-of-words model). This would give you a fixed size vector for every training and testing image.