我的目标是将图像作为查询并在图像库中找到它的最佳匹配.我在openCV 3.0.0中使用SURF功能,并使用Bag of Words方法找到匹配项.我需要一种方法来查明查询图像是否在库中匹配.如果是这样,我想知道最接近匹配的图像的索引.
这是我的所有图像读取代码(图像库中共300个)并提取和聚类功能:
Mat training_descriptors(1, extractor->descriptorSize(), extractor->descriptorType());
//read in all images and set to binary
char filepath[1000];
for (int i = 1; i < trainingSetSize; i++){
cout << "in for loop, iteration: " << i << endl;
_snprintf_s(filepath, 100, "C:/Users/Randal/Desktop/TestCase1Training/%d.bmp", i);
Mat temp = imread(filepath, CV_LOAD_IMAGE_GRAYSCALE);
Mat tempBW;
adaptiveThreshold(temp, tempBW, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 11, 2);
detector->detect(tempBW, keypoints1);
extractor->compute(tempBW, keypoints1, descriptors1);
training_descriptors.push_back(descriptors1);
cout << "descriptors added" << endl;
}
cout << "Total descriptors: " << training_descriptors.rows << endl;
trainer.add(training_descriptors); …Run Code Online (Sandbox Code Playgroud)