Skip to content

Commit a84afb6

Browse files
committed
Merge pull request opencv#17640 from pemmanuelviel:pev--fix-lsh-bad-any-cast
2 parents cabad90 + cdac7c7 commit a84afb6

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

modules/flann/include/opencv2/flann/lsh_index.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ struct LshIndexParams : public IndexParams
6060
{
6161
LshIndexParams(unsigned int table_number = 12, unsigned int key_size = 20, unsigned int multi_probe_level = 2)
6262
{
63-
(* this)["algorithm"] = FLANN_INDEX_LSH;
63+
(*this)["algorithm"] = FLANN_INDEX_LSH;
6464
// The number of hash tables to use
65-
(*this)["table_number"] = table_number;
65+
(*this)["table_number"] = static_cast<int>(table_number);
6666
// The length of the key in the hash tables
67-
(*this)["key_size"] = key_size;
67+
(*this)["key_size"] = static_cast<int>(key_size);
6868
// Number of levels to use in multi-probe (0 for standard LSH)
69-
(*this)["multi_probe_level"] = multi_probe_level;
69+
(*this)["multi_probe_level"] = static_cast<int>(multi_probe_level);
7070
}
7171
};
7272

@@ -94,9 +94,9 @@ class LshIndex : public NNIndex<Distance>
9494
{
9595
// cv::flann::IndexParams sets integer params as 'int', so it is used with get_param
9696
// in place of 'unsigned int'
97-
table_number_ = (unsigned int)get_param<int>(index_params_,"table_number",12);
98-
key_size_ = (unsigned int)get_param<int>(index_params_,"key_size",20);
99-
multi_probe_level_ = (unsigned int)get_param<int>(index_params_,"multi_probe_level",2);
97+
table_number_ = get_param(index_params_,"table_number",12);
98+
key_size_ = get_param(index_params_,"key_size",20);
99+
multi_probe_level_ = get_param(index_params_,"multi_probe_level",2);
100100

101101
feature_size_ = (unsigned)dataset_.cols;
102102
fill_xor_mask(0, key_size_, multi_probe_level_, xor_masks_);
@@ -112,7 +112,7 @@ class LshIndex : public NNIndex<Distance>
112112
void buildIndex() CV_OVERRIDE
113113
{
114114
tables_.resize(table_number_);
115-
for (unsigned int i = 0; i < table_number_; ++i) {
115+
for (int i = 0; i < table_number_; ++i) {
116116
lsh::LshTable<ElementType>& table = tables_[i];
117117
table = lsh::LshTable<ElementType>(feature_size_, key_size_);
118118

@@ -378,11 +378,11 @@ class LshIndex : public NNIndex<Distance>
378378
IndexParams index_params_;
379379

380380
/** table number */
381-
unsigned int table_number_;
381+
int table_number_;
382382
/** key size */
383-
unsigned int key_size_;
383+
int key_size_;
384384
/** How far should we look for neighbors in multi-probe LSH */
385-
unsigned int multi_probe_level_;
385+
int multi_probe_level_;
386386

387387
/** The XOR masks to apply to a key to get the neighboring buckets */
388388
std::vector<lsh::BucketKey> xor_masks_;

modules/flann/test/test_lshtable_badarg.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,10 @@ void CV_LshTableBadArgTest::run( int /* start_from */ )
9090

9191
TEST(Flann_LshTable, badarg) { CV_LshTableBadArgTest test; test.safe_run(); }
9292

93+
TEST(Flann_LshTable, bad_any_cast) {
94+
Mat features = Mat::ones(1, 64, CV_8U);
95+
EXPECT_NO_THROW(flann::GenericIndex<cvflann::Hamming2<unsigned char> >(
96+
features, cvflann::LshIndexParams()));
97+
}
98+
9399
}} // namespace

0 commit comments

Comments
 (0)