Ask Your Question

Running into an error using cv::BFMatcher (bruteforce matcher) with 10,100 training images

asked 2013-02-07 13:22:17 -0600

bfmatcher_hurts gravatar image

updated 2013-02-08 07:36:58 -0600

I'm implementing a simple bag-of-words matching system, where I have 10,100 "clusters" and I am trying to match a single feature vector to the closest cluster. This works for a smaller number of clusters, but I need it to work for this larger set.

Essentially, I put all 10,100 clusters into a vector of cv::Mat objects, each of which is 1 x 16. Then, I add these to the BFMatcher as follows:

cv::BFMatcher matcher(cv::NORM_HAMMING);

Finally, given a new 1 x 16 feature vector to match, I do the following:

std::vector<cv::DMatch> matches;
bf_matcher.match(feature_vector, matches);

The error I get is the following:

OpenCV Error: Assertion failed ((int64)imgCount*IMGIDX_ONE < INT_MAX) in unknown function, file ......\src\opencv\modules\features2d\src\matchers.cpp, line 360

My question is simple, what is going on and how can I make this work? It's pretty clear that for some reason it considers 10,100 to be too many training instances, but that is extremely small in comparison to some other applications.

edit retag flag offensive close merge delete


Just out of curiosity: How do you cluster your binary features?

Guanta gravatar imageGuanta ( 2013-02-09 09:10:53 -0600 )edit

@Guanta You can cluster binary features with k-means, using hamming distance as the distance metric (you can't do that with OpenCV's k-means, but it's pretty easy to code yourself). I'm trying a few different approaches out

bfmatcher_hurts gravatar imagebfmatcher_hurts ( 2013-02-11 09:18:24 -0600 )edit

Okay, but what how do you compute the means of binary vectors? Or do you take then the median?

Guanta gravatar imageGuanta ( 2013-02-12 04:15:24 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-02-09 09:09:50 -0600

Guanta gravatar image

Hmm, very weired, I am doing nearly the same without a problem. So let's look at matchers.cpp: imgCount would be the numbers of clusters, i.e. 10100 in your case. According to matchers.cpp IMGIDX_ONE = (1 << 18) = 2^18 = 262144. So 10100*262144 = 2 647 654 400. If INT_MAX is 2^31 - 1 = 2 147 483 647 the assertion fails. However, depending on your system and the compiler you use, see, INT_MAX can vary. I'm not very sure about the meaning of this assertion, but maybe this assertion could be changed to UINT_MAX then you wouldn't have a problem, i.e. changing INT_MAX to UINT_MAX in matchers.cpp and recompiling opencv may solve your problem for now.

edit flag offensive delete link more


Very strange. This must be it. I'm currently using the windows superpack, so I guess I'll have to go recompile my own opencv binaries, but what you wrote looks reasonable. It seems like such an odd requirement. In the meantime, I wrote my own brute-force matcher and it has no such requirements. I'm not sure why that assertion would exist. Thanks

bfmatcher_hurts gravatar imagebfmatcher_hurts ( 2013-02-11 09:20:58 -0600 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-02-07 13:22:17 -0600

Seen: 625 times

Last updated: Feb 09 '13