Bruteforce and matching giving reverse results. Why?

asked 2013-05-01 09:00:19 -0600

MysticBE gravatar image

updated 2013-05-02 09:15:18 -0600

I've been making an application where 2 images can be compared (2 pictures on my smartphone). There I use a FAST detector and FREAK descriptor on a limited amount of keypoints (i filtered out the 300 best ones according to the response). When I try to match it with BRUTEFORCE_HAMMING, it gives back 0 matches.

Matching happens with

    MatOfDMatch matches = new MatOfDMatch();

    matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
    matcher.match(descriptors,descriptors1,matches);
    MatOfDMatch goedematches = new MatOfDMatch();

    double max_dist = 0;
    double min_dist = 100;
    //if (descriptors.cols() == descriptors1.cols())
    //{
    for( int i = 0; i < descriptors.rows(); i++ )
    { double dist = matches.toArray()[i].distance;
      if( dist < min_dist ) min_dist = dist;
      if( dist > max_dist ) max_dist = dist;
    }
    // should only draw good matches
   for( int i = 0; i < descriptors.rows(); i++ )
    {  MatOfDMatch temp = new MatOfDMatch();
       if( matches.toArray()[i].distance < 2*min_dist )
       {   temp.fromArray(matches.toArray()[i]);
           goedematches.push_back(temp); 
           }        
   // }
    }

   Log.d("LOG!", "Number of good matches= " + goedematches.size());

When I compare the image to itself, I get the following output. The output is 0x0 good matches.

image description

05-02 15:52:30.325: D/LOG!(17866): Number of Descriptors image 1= 64x286
05-02 15:52:30.325: D/LOG!(17866): Number of Descriptors image 2= 64x286
05-02 15:52:30.325: D/LOG!(17866): description time elapsed 339 ms
05-02 15:52:30.555: D/LOG!(17866): Minimum distance = 0.0
05-02 15:52:30.560: D/LOG!(17866): Maximum distance= 0.0
05-02 15:52:30.560: D/LOG!(17866): Number of good matches= 0x0

When I use the same picture and one that has nothing to do with it, I get about 471 matches. There is something wrong inside the code, but I can't seem to see what's wrong (the code seems to reserve, cause everything that is the same isn't matched, and it's matched when it's completely different. Where is the code am I doing it wrong?)

IMPORTANT: Don't mind the red dots on the right picture, it's just an old picture I took when I drew the keypoints on the screen. It does not stand for the matching itself! It could be any other picture that has nothing to do with the first image.

image description

05-02 16:03:06.120: D/LOG!(19025): Number of Descriptors image 1= 64x259
05-02 16:03:06.120: D/LOG!(19025): Number of Descriptors image 2= 64x286
05-02 16:03:06.420: D/LOG!(19025): Minimum distance= 93.0
05-02 16:03:06.420: D/LOG!(19025): Maximum distance = 183.0
05-02 16:03:06.420: D/LOG!(19025): Number of good matches= 1x286

This Question has been posted on Stackoverflow as well.

edit retag flag offensive close merge delete

Comments

You might link the StackOverflow question you also posted...

Nyenna gravatar imageNyenna ( 2013-05-01 12:25:19 -0600 )edit

I will be sure to do that, but it currently hasn't given me a right answer yet. I currently get more "good matches" with an image that has nothing to do with the original, than an image that is basically the original image..

MysticBE gravatar imageMysticBE ( 2013-05-01 18:46:36 -0600 )edit

I believe you should use the hamming distance with the BFMatcher (since you are using binary descriptors). Have you tried to draw the matches? If you believe that your matching is incorrect, you might want to share us a picture of your results.

Nyenna gravatar imageNyenna ( 2013-05-02 00:57:57 -0600 )edit

@MysticBE: Your problem is solved at your StackOverflow link. If you have further question please update your question or ask a separate one.

Guanta gravatar imageGuanta ( 2013-05-02 05:20:16 -0600 )edit

updated my question, and gave more information. The sentence in the image that says "Aantal goeie matches" means 'Number of good matches'.

MysticBE gravatar imageMysticBE ( 2013-05-02 08:02:59 -0600 )edit

The code in your question is using BRUTEFORCE_SL2, and you should use BRUTEFORCE_HAMMING. Did you change this? How many matches do you have before the filtering?

Nyenna gravatar imageNyenna ( 2013-05-02 09:10:55 -0600 )edit

yes I did, just completely updated my code ;) should be more clear now

MysticBE gravatar imageMysticBE ( 2013-05-02 09:16:27 -0600 )edit