Skip to content

Commit daa88c6

Browse files
Merge pull request opencv#17642 from pemmanuelviel:pev--fixes-and-clean
* Clean: make the use of the indices array length consistent Either we don't want this method to be used in the future for any other node than the root node, and so we replace indices_length by size_ and remove it as argument, or we want to be able to use it potentially for other nodes, and so using size_ instead of indices_length would have lead to a bug. * Fix: b was not an address * Fix: transpose the Flann repo commit "Fixes in accum_dist methods" from Adil Ibragimov Avoids trying to compute log(ratio) with ratio = 0 * Fix: transpose the Flann repo commit "result_set bugfix" from Jack Rae * Fix Jack Rae commit as the initial i - 1 index was decremented before entering the loop body * Clean: transpose the Flann repo commit "Updated comments in lsh_index" from Richard McPherson * Fix: Transpose the Flann repo commit "Fixing unreachable code in lsh_table.h" from hypevr * Fix warning the same way it was done in flann standalone repo * Change the return value in case of unsupported type
1 parent e45d74c commit daa88c6

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

modules/flann/include/opencv2/flann/dist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ struct KL_Divergence
708708
Iterator1 last = a + size;
709709

710710
while (a < last) {
711-
if (* b != 0) {
711+
if ( *a != 0 && *b != 0 ) {
712712
ResultType ratio = (ResultType)(*a / *b);
713713
if (ratio>0) {
714714
result += *a * log(ratio);
@@ -731,7 +731,7 @@ struct KL_Divergence
731731
inline ResultType accum_dist(const U& a, const V& b, int) const
732732
{
733733
ResultType result = ResultType();
734-
if( *b != 0 ) {
734+
if( a != 0 && b != 0 ) {
735735
ResultType ratio = (ResultType)(a / b);
736736
if (ratio>0) {
737737
result = a * log(ratio);

modules/flann/include/opencv2/flann/kmeans_index.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ class KMeansIndex : public NNIndex<Distance>
650650
*
651651
* Params:
652652
* node = the node to use
653-
* indices = the indices of the points belonging to the node
653+
* indices = array of indices of the points belonging to the node
654+
* indices_length = number of indices in the array
654655
*/
655656
void computeNodeStatistics(KMeansNodePtr node, int* indices, int indices_length)
656657
{
@@ -662,7 +663,7 @@ class KMeansIndex : public NNIndex<Distance>
662663

663664
memset(mean,0,veclen_*sizeof(DistanceType));
664665

665-
for (size_t i=0; i<size_; ++i) {
666+
for (size_t i=0; i<(size_t)indices_length; ++i) {
666667
ElementType* vec = dataset_[indices[i]];
667668
for (size_t j=0; j<veclen_; ++j) {
668669
mean[j] += vec[j];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ struct LshIndexParams : public IndexParams
7171
};
7272

7373
/**
74-
* Randomized kd-tree index
74+
* Locality-sensitive hashing index
7575
*
76-
* Contains the k-d trees and other information for indexing a set of points
76+
* Contains the tables and other information for indexing a set of points
7777
* for nearest-neighbor matching.
7878
*/
7979
template<typename Distance>

modules/flann/include/opencv2/flann/lsh_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class LshTable
245245
{
246246
std::cerr << "LSH is not implemented for that type" << std::endl;
247247
assert(0);
248-
return 1;
248+
return 0;
249249
}
250250

251251
/** Get statistics about the table

modules/flann/include/opencv2/flann/result_set.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,10 @@ class KNNResultSet : public ResultSet<DistanceType>
196196
#endif
197197
{
198198
// Check for duplicate indices
199-
int j = i - 1;
200-
while ((j >= 0) && (dists[j] == dist)) {
199+
for (int j = i; dists[j] == dist && j--;) {
201200
if (indices[j] == index) {
202201
return;
203202
}
204-
--j;
205203
}
206204
break;
207205
}

0 commit comments

Comments
 (0)