问题
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:
- Compute the features for each image of the training set
- Cluster those features
- 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:
- Compute the features of the test image
- For each feature, find the nearest cluster
- Add a tick for each training image that belong to this cluster
- Repeat for all features of the test image
- 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