FAST と FREAK を使用していくつかの画像の記述子を取得し、次に knnMatch をBruteForceMatcher マッチャーに適用し、次にループを使用して適切な一致を分離しています。
float nndrRatio = 0.7f;
std::vector<KeyPoint> keypointsA, keypointsB;
Mat descriptorsA, descriptorsB;
std::vector< vector< DMatch > > matches;
int threshold=9;
// detect keypoints:
FAST(objectMat,keypointsA,threshold,true);
FAST(sceneMat,keypointsB,threshold,true);
FREAK extractor;
// extract descriptors:
extractor.compute( objectMat, keypointsA, descriptorsA );
extractor.compute( sceneMat, keypointsB, descriptorsB );
BruteForceMatcher<Hamming> matcher;
// match
matcher.knnMatch(descriptorsA, descriptorsB, matches, 2);
// good matches search:
vector< DMatch > good_matches;
for (size_t i = 0; i < matches.size(); ++i)
{
if (matches[i].size() < 2)
continue;
const DMatch &m1 = matches[i][0];
const DMatch &m2 = matches[i][1];
if(m1.distance <= nndrRatio * m2.distance)
good_matches.push_back(m1);
}
//If there are at least 7 good matches, then object has been found
if ( (good_matches.size() >=7))
{
cout << "OBJECT FOUND!" << endl;
}
FlannBasedMatcher と一緒に使用すると問題なく動作しますが、BruteForceMatcher と一緒に使用すると非常に奇妙になるため、問題は適切な一致検索方法である可能性があると思います。ハミング距離はバイナリ記述子を使用するため、この方法でナンセンスを行っているのではないかと疑っていますが、それを適応させる方法が思いつきません!
リンク、スニペット、アイデアなどはありますか?