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

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);
bf_matcher.add(clusters_for_matching);
```

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.

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

Guanta ( 2013-02-09 09:10:53 -0500 )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 ( 2013-02-11 09:18:24 -0500 )editOkay, but what how do you compute the means of binary vectors? Or do you take then the median?

Guanta ( 2013-02-12 04:15:24 -0500 )edit