how to use SIFT features for bag of words in opencv?

╄→尐↘猪︶ㄣ 提交于 2019-12-06 05:52:28

问题


I have read a lot of articles about implementing bag of words after taking sift features of an image, but I'm still confused what to do next. What do i specifically do?

Thank you so much in advance for the guidance.

This is the code that i have so far.

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);

回答1:


Training a bag of words system goes as follows:

  1. Compute the features for each image of the training set
  2. Cluster those features
  3. Label each cluster with the images that have features in that cluster

At this point the training is done and you can start with the testing as follows:

  1. Compute the features of the test image
  2. For each feature, find the nearest cluster
  3. Add a tick for each training image that belong to this cluster
  4. Repeat for all features of the test image
  5. The image that has the highest number of ticks is the best match and the image with the second highest number of ticks is the second best match and so on

As you can notice, there is no restriction to using SIFT. You can try different feature extractors and descriptors.



来源:https://stackoverflow.com/questions/30928135/how-to-use-sift-features-for-bag-of-words-in-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!