From: Pierre-Emmanuel Viel Date: Thu, 26 Dec 2013 18:44:23 +0000 (+0100) Subject: Avoid obtaining several identical dimensions between two LSH sub-vectors by choosing... X-Git-Tag: submit/tizen_ivi/20141117.190038~2^2~198^2~7^2~1^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e85bacff7b676a7789bea6501e694cac299b21be;p=profile%2Fivi%2Fopencv.git Avoid obtaining several identical dimensions between two LSH sub-vectors by choosing orthogonal sub-vectors. --- diff --git a/modules/flann/include/opencv2/flann/lsh_table.h b/modules/flann/include/opencv2/flann/lsh_table.h index b0f3223..6b8d614 100644 --- a/modules/flann/include/opencv2/flann/lsh_table.h +++ b/modules/flann/include/opencv2/flann/lsh_table.h @@ -348,13 +348,21 @@ inline LshTable::LshTable(unsigned int feature_size, unsigned int mask_ = std::vector((size_t)ceil((float)(feature_size * sizeof(char)) / (float)sizeof(size_t)), 0); // A bit brutal but fast to code - std::vector indices(feature_size * CHAR_BIT); - for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = i; - std::random_shuffle(indices.begin(), indices.end()); + static std::vector indices(feature_size * CHAR_BIT); + + //Ensure the Nth bit will be selected only once among the different LshTables + //to avoid having two different tables with signatures sharing many dimensions/many bits + if( (indices.size() == feature_size * CHAR_BIT) || (indices.size() < key_size_) ) + { + indices.resize( feature_size * CHAR_BIT ); + for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = i; + std::random_shuffle(indices.begin(), indices.end()); + } // Generate a random set of order of subsignature_size_ bits for (unsigned int i = 0; i < key_size_; ++i) { - size_t index = indices[i]; + size_t index = indices[0]; + indices.erase( indices.begin() ); // Set that bit in the mask size_t divisor = CHAR_BIT * sizeof(size_t);