Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Object Detection with Freak (Hamming)

Hi, I am using FAST and FREAK to get the descriptors of a couple of images and then I apply knnMatch with a cv::BFMatcher matcher(cv::NORM_HAMMING); and next I am using a loop to separate the good matches:

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

  cv::BFMatcher matcher(cv::NORM_HAMMING);
       // 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;
  }

I think the problem could be the good matches search method, because using it with the FlannBasedMatcher works fine but with the BruteForceMatcher very weirdly. I'm suspecting that I may be doing a nonsense with these method because Hamming distance uses binary descriptors, but I can't think of a way to adapt it!

Any links, snippets, ideas,... please?