Ask Your Question

Str1101's profile - activity

2016-01-24 02:23:48 -0600 received badge  Notable Question (source)
2015-01-25 08:32:38 -0600 received badge  Popular Question (source)
2013-06-25 17:09:29 -0600 commented question Object Detection with Freak (Hamming)

My problem is, basically, that I don't know how to use the matches that returns the knnMatch to detect when the object of the image1 is inside the image2 and when isn't.

2013-06-25 16:20:41 -0600 asked a question 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:

  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)      

        const DMatch &m1 = matches[i][0];   
        const DMatch &m2 = matches[i][1];

        if(m1.distance <= nndrRatio * m2.distance)        

       //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?