Ask Your Question
0

Object Detection with Freak (Hamming)

asked 2013-06-25 16:20:41 -0600

Str1101 gravatar image

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?

edit retag flag offensive close merge delete

Comments

you didn't say which is exactly the problem, we can't help

yes123 gravatar imageyes123 ( 2013-06-25 16:54:59 -0600 )edit

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.

Str1101 gravatar imageStr1101 ( 2013-06-25 17:09:29 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-08-02 03:42:18 -0600

ximobayo gravatar image

The matchs returns the distance to the matched descriptor. So you can compare the nearest match with the next I mean:

We have 1 well-know feature from our object and we want to check a set of input features.

After compute the descriptors you call the knnmatch. now we can check how good is the nearest match. if the distance to the neares is less than the second match *factor we accept like the feature.

For example with surf features the autos at their paper I remember that use a 0.6 as factor. So follow this criterion if the distance of the nearest match is less or equal than the distance of 2-th nearest macht * 0.6 the feature is found.

edit flag offensive delete link more

Comments

http://code.google.com/p/itlab-computer-vision/source/browse/trunk/Belousov/filter.h?r=33

I can also recommend this header file. It contains different ways to filter matches, also the one that you proposed.

Moster gravatar imageMoster ( 2013-08-02 05:55:49 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2013-06-25 16:20:41 -0600

Seen: 4,873 times

Last updated: Aug 02 '13