DescriptorMatcher enable Cross Check

asked 2013-04-12 04:58:17 -0500

Andriy gravatar image

I'm using OpenCV with support for Java Desktop. I'm trying to match key points of two different images with DescriptorMatcher. Then I'm applying the Good Matches check and everything works fine. But I've noticed that exists another methodology to eliminate bad matches, the name of which is Cross Check.

1) Is it possible to activate it on definition of matcher?

I've also tried to create my own function, that performs the Cross Check, but something is wrong my code as it returns only 1 match.

2) What can be wrong in the following code?

DescriptorMatcher matcherknn = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);
matcherknn.match(d1,d2, matchesknn12);
matcherknn.match(d2,d1, matchesknn21);
List <DMatch> matches12 = matchesknn12.toList();
List <DMatch> matches21 = matchesknn21.toList();
List <DMatch> filteredMatches = new ArrayList<DMatch>();

for( int fk = 0; fk < matches12.size(); fk++ )
{
    DMatch forward = matches12.get(fk);    
    DMatch backward = matches21.get(forward.trainIdx);
    if( backward.trainIdx != forward.queryIdx ){
        filteredMatches.add(forward);
        break;
    }

}
edit retag flag offensive close merge delete