Ask Your Question
1

Ratio check function with findHomography

asked 2013-08-20 13:07:42 -0600

matteo gravatar image

updated 2013-08-21 08:33:00 -0600

SR gravatar image

i need to acquire a perspective matrix from two images taken by the same camera after its movement in a 3D space...I'm taking inspiration from this OpenCV's example about the use of findHomography. I would like to substitute the "filter for the good_matches there suggested with the "ratio check function":

class RatioCheck
{
public:
    RatioCheck(){};
    void filter(vector<vector<DMatch>>& nmatches, double RatioT);
};

void RatioCheck::filter(std::vector<vector<DMatch> > &nmatches, double RatioT=0.8)
{
    vector<vector<DMatch>> knmatches;
    for(int i=0; i<nmatches.size(); i++)
    {
        if((nmatches[i].size()==1)||...
            (abs(nmatches[i][0].distance/nmatches[i][1].distance) <RatioT))
        {
            knmatches.push_back(nmatches[i]);
        }
    }
    nmatches=knmatches;
}

In principle i have to give to the function a vector<vector<DMatch> > ..but actually i have a vector<DMatch>... does anybody know how?

edit retag flag offensive close merge delete

Comments

-1. Relevant part of the question off-site. Provide a minimal example.

SR gravatar imageSR ( 2013-08-20 16:27:12 -0600 )edit
1

updated..sorry

matteo gravatar imagematteo ( 2013-08-21 04:10:50 -0600 )edit

+1 Thanks. (seems that I cannot undo my downvote, so I upvoted your comment)

SR gravatar imageSR ( 2013-08-21 08:27:37 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-08-20 13:36:35 -0600

Moster gravatar image

updated 2013-08-21 02:03:09 -0600

You need to replace the matching part with this. Its important that you use knnMatch with 2 best matches, so that you can actually do the ratioTest (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]);
   }
}

The 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 );
}
edit flag offensive delete link more

Comments

-1. Solution off-site.

SR gravatar imageSR ( 2013-08-20 16:25:37 -0600 )edit

Why isnt it allowed to be offsite? I didnt want to post the whole code here, since its huge and he hasnt been too specific.

Moster gravatar imageMoster ( 2013-08-21 00:58:32 -0600 )edit
1

Because a specific question should be asked where the OP narrows it down to the actual issue. Posting the whole code is not really helpful as one has to scan the whole code. And also, the answer should be reachable for everyone. External links might be dead soon.

SR gravatar imageSR ( 2013-08-21 01:26:10 -0600 )edit
1

Ok, I edited it, so that its not leading to an offsite.

Moster gravatar imageMoster ( 2013-08-21 02:05:04 -0600 )edit
1

+1. Thanks!

SR gravatar imageSR ( 2013-08-21 08:33:40 -0600 )edit

Question Tools

Stats

Asked: 2013-08-20 13:07:42 -0600

Seen: 1,273 times

Last updated: Aug 21 '13