Training SVM classifier in OpenCV using SIFT and ORB functions

I am trying to prepare an SVM classifier for recognizing pedestrians in a 64x128 image set. I already did this using HOG functions, and now I need to implement the same thing using SIFT and ORB. For HOG functions, I always had the same number of functions (3780), so the matrix for the train was image_number at 3780. Now, using the SIFT extractor, I get key points of different sizes. How to create a matrix for the classifier using these key points of different sizes?

Many thanks for your help!

I solved the problem with descriptors by putting all of them on the same line. However, I found that most descriptors have a value of 0, so the classifier does not work. Do you know how I can solve this problem?

This is a piece of 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 
+4
source share
2 answers

Typically, people vector-quantize SIFT or ORB functions and plot histograms (word bag model). This will give you a fixed vector size for each training and test image.

+5
source

You can create a large matrix and push_back descriptors calculated for each image. Example (not checked)

 int main(int argc, char**argv) { cv::SIFT sift; cv::Mat dataMatrix(0, 128, CV_32F); // 0 rows, 128 cols is SIFT dimension, I think there is a method that gives you the descriptor dimension exactly. type is 32F if I remember well, must check for (int i = 1; i < argc; ++i) { cv::Mat img = cv::imread(argv[i]); std::vector<cv::KeyPoints> kp; cv::Mat desc; sift(img, cv::noArray(), keypoints, desc); dataMatrix.push_back(desc); } // Now train SVM with dataMatrix assert(dataMatrix.rows > 0); } 
+1
source

Source: https://habr.com/ru/post/1436343/


All Articles