BFMatcher (Bug #3172)


Added by Robert Aschenbrenner over 11 years ago. Updated over 9 years ago.


Status:Open Start date:2013-07-24
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:features2d
Target version:-
Affected version:2.4.9 (latest release) Operating System:Linux
Difficulty: HW Platform:x64
Pull request:https://github.com/Itseez/opencv/pull/3025

Description

Using BFMatcher with "NORM_HAMMING" on binary descriptors (created by FREAK) gives unexpected results in certain conditions:

std::vector<Mat> descriptors; //FREAK descriptors of e.g. 1000 images
... //compute actual descriptors
BFMatcher bfMatcher(NORM_HAMMING, false);
bfMatcher.add(descriptors);
int nn = 10; //Number of nearest neighbours
bfMatcher.knnMatch(query_descriptors, matches, nn);

The above code returns invalid results, if nn happens to be smaller than any image's descriptor set.
For example one single image test.jpg might have only 9 (<nn) according FREAK descriptors.
The BFMatcher will calculate all distances using batchDistance (https://github.com/Itseez/opencv/blob/master/modules/features2d/src/matchers.cpp#L366).
Eventually it passes the current best results (nidx) to cv::batchDistance in https://github.com/Itseez/opencv/blob/master/modules/core/src/stat.cpp#L1792.
The problem arises in the following section:

 K = std::min(K, src2.rows);

    _dist.create(src1.rows, (K > 0 ? K : src2.rows), dtype);
    Mat dist = _dist.getMat(), nidx;
    if( _nidx.needed() )
    {
        _nidx.create(dist.size(), CV_32S);
        nidx = _nidx.getMat();
    }

K is reduced, when test.jpg (src2) is inspected, since it only has 9 rows.
_nidx.create(dist.size(), CV_32S); reduces the dimension of nidx to 9 columns, invalidating older results.
Later images may increase the column size again to 10.
The assumption, that the number of descriptors of every image is always > nn, seems unenforced.


Associated revisions

Revision 4c404cb4
Added by Alexander Alekhin over 10 years ago

Merge pull request #3172 from ilya-lavrenov:tapi_transpose_amd

History

Updated by Ivan Korolev over 11 years ago

Hi Robert,
thanks for the bug report. Do you think you can fix the problem? If you could investigate this issue or send a fixing pull request (http://www.code.opencv.org/projects/opencv/wiki/How_to_contribute for more details) your help would be highly appreciated!

Updated by Ivan Korolev over 11 years ago

  • Status changed from New to Open

Updated by Robert Aschenbrenner over 11 years ago

Hi, I am afraid that I do not have sufficient time at the moment. In my code I'm circumventing the above mentioned case by extra checks.
I suspect the code in stat.cpp is not only used by BFMatcher.
Maybe the original author could have a look?

Updated by Philipp Hasper over 10 years ago

Unfortunately it seems that I don't have the rights to assign a pull request to this issue. So I have to paste the URL manually: https://github.com/Itseez/opencv/pull/3025

Updated by Alexander Karsakov over 10 years ago

  • Pull request set to https://github.com/Itseez/opencv/pull/3025
  • Affected version changed from 2.4.0 - 2.4.5 to 2.4.9 (latest release)
  • Assignee deleted (Maria Dimashova)

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4600

Also available in: Atom PDF