How to use SIFT functions for bag of words in opencv?

I've read a lot of articles about implementing a word package after adopting the sifting functions of an image, but I'm still confused as to what to do next. What am I doing specifically?

Thank you in advance for the guidance.

This is the code I have.

cv::Mat mat_img = cropped.clone();
Mat grayForML;
cvtColor(mat_img, grayForML, CV_BGR2GRAY);
IplImage grayImageForML = grayForML.operator IplImage();


//create another copy of iplGray
IplImage *input = cvCloneImage(&grayImageForML);
Mat matInput = cvarrToMat(input);
//  Mat matInput = copy_gray.clone();
cv::SiftFeatureDetector detector;
std::vector<cv::KeyPoint> keyPoints;
detector.detect(input, keyPoints);
//add results to image and save.
cv::Mat output;
cv::drawKeypoints(input, keyPoints, output);    //SIFT OUTPUT RESULT


//resize and display
cv::Mat output_reduced;
cv::resize(output, output_reduced, cv::Size2i(output.cols / 2, output.rows / 2));


imshow("SIFT result", output_reduced);

      

+3


source to share


1 answer


Training the batch word system looks like this:

  • Compute functions for each image of the training set
  • Group these functions
  • Name each cluster as images that have functions in that cluster

At this stage, training is carried out and you can start with testing as follows:



  • Calculate Test Image Functions
  • For each function, find the closest cluster
  • Add a check mark for each training image that belongs to this cluster
  • Repeat all functions of the test pattern
  • The best match has the image with the most ticks, the image with the second highest tick count has the second best match, and so on.

As you can see, there are no restrictions on the use of SIFT. You can try various function extractors and descriptors.

+3


source







All Articles