From daa88c6b9e1c5a4fea6fa4343cc9132f40419732 Mon Sep 17 00:00:00 2001
From: pemmanuelviel
Date: Sat, 27 Jun 2020 00:34:52 +0200
Subject: [PATCH] Merge pull request #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
---
modules/flann/include/opencv2/flann/dist.h | 4 ++--
modules/flann/include/opencv2/flann/kmeans_index.h | 5 +++--
modules/flann/include/opencv2/flann/lsh_index.h | 4 ++--
modules/flann/include/opencv2/flann/lsh_table.h | 2 +-
modules/flann/include/opencv2/flann/result_set.h | 4 +---
5 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h
index 07a1cc29c6..b092b531a1 100644
--- a/modules/flann/include/opencv2/flann/dist.h
+++ b/modules/flann/include/opencv2/flann/dist.h
@@ -708,7 +708,7 @@ struct KL_Divergence
Iterator1 last = a + size;
while (a < last) {
- if (* b != 0) {
+ if ( *a != 0 && *b != 0 ) {
ResultType ratio = (ResultType)(*a / *b);
if (ratio>0) {
result += *a * log(ratio);
@@ -731,7 +731,7 @@ struct KL_Divergence
inline ResultType accum_dist(const U& a, const V& b, int) const
{
ResultType result = ResultType();
- if( *b != 0 ) {
+ if( a != 0 && b != 0 ) {
ResultType ratio = (ResultType)(a / b);
if (ratio>0) {
result = a * log(ratio);
diff --git a/modules/flann/include/opencv2/flann/kmeans_index.h b/modules/flann/include/opencv2/flann/kmeans_index.h
index 7574e7faf8..f743d75224 100644
--- a/modules/flann/include/opencv2/flann/kmeans_index.h
+++ b/modules/flann/include/opencv2/flann/kmeans_index.h
@@ -650,7 +650,8 @@ private:
*
* Params:
* node = the node to use
- * indices = the indices of the points belonging to the node
+ * indices = array of indices of the points belonging to the node
+ * indices_length = number of indices in the array
*/
void computeNodeStatistics(KMeansNodePtr node, int* indices, int indices_length)
{
@@ -662,7 +663,7 @@ private:
memset(mean,0,veclen_*sizeof(DistanceType));
- for (size_t i=0; i
diff --git a/modules/flann/include/opencv2/flann/lsh_table.h b/modules/flann/include/opencv2/flann/lsh_table.h
index db8b5af946..8f5250171b 100644
--- a/modules/flann/include/opencv2/flann/lsh_table.h
+++ b/modules/flann/include/opencv2/flann/lsh_table.h
@@ -245,7 +245,7 @@ public:
{
std::cerr << "LSH is not implemented for that type" << std::endl;
assert(0);
- return 1;
+ return 0;
}
/** Get statistics about the table
diff --git a/modules/flann/include/opencv2/flann/result_set.h b/modules/flann/include/opencv2/flann/result_set.h
index 735028fb45..02f827ada0 100644
--- a/modules/flann/include/opencv2/flann/result_set.h
+++ b/modules/flann/include/opencv2/flann/result_set.h
@@ -196,12 +196,10 @@ public:
#endif
{
// Check for duplicate indices
- int j = i - 1;
- while ((j >= 0) && (dists[j] == dist)) {
+ for (int j = i; dists[j] == dist && j--;) {
if (indices[j] == index) {
return;
}
- --j;
}
break;
}