Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Thats actually pretty easy. I modified the code for you. I didnt check it with a compiler though

http://pastebin.com/AdZZP18V

Thats You need to replace the matching part with this. Its important that you use knnMatch with 2 best matches, so that you can actually pretty easy. I modified do the code for you. I didnt check it with a compiler thoughratioTest (which compares the match distance between the first and second best match).

std::vector<vector< DMatch >> matches;
matcher.knnMatch( descriptors_object, descriptors_scene, matches, 2 );

std::vector<vector<DMatch>> good_matches
double RatioT = 0.75;
//-- ratio Test
for(int i=0; i<matches.size(); i++)
{
   if((matches[i].size()==1)||(abs(matches[i][0].distance/matches[i][1].distance) < RatioT))
   {
      good_matches.push_back(matches[i]);
   }
}

http://pastebin.com/AdZZP18VThe creation of the Point2f vectors obj and scene also needs to be adjusted since you have a vector of vectors.

for( int i = 0; i < good_matches.size(); i++ )
{
//-- Get the keypoints from the good matches
    obj.push_back( keypoints_object[ good_matches[i][0].queryIdx ].pt );
    scene.push_back( keypoints_scene[ good_matches[i][0].trainIdx ].pt );
}