Merge pull request #17642 from pemmanuelviel:pev--fixes-and-clean
authorpemmanuelviel <p.emmanuel.viel@gmail.com>
Fri, 26 Jun 2020 22:34:52 +0000 (00:34 +0200)
committerGitHub <noreply@github.com>
Fri, 26 Jun 2020 22:34:52 +0000 (22:34 +0000)
* 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
modules/flann/include/opencv2/flann/kmeans_index.h
modules/flann/include/opencv2/flann/lsh_index.h
modules/flann/include/opencv2/flann/lsh_table.h
modules/flann/include/opencv2/flann/result_set.h

index 07a1cc29c6e807c177093e0c020f923cea644f87..b092b531a18732cd6fb6b8ee3fcb8e6daa0022ab 100644 (file)
@@ -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);
index 7574e7faf8b03359898cce04ad235f5d19c05573..f743d75224176fbbdeab883c629cd319b29a9731 100644 (file)
@@ -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<size_; ++i) {
+        for (size_t i=0; i<(size_t)indices_length; ++i) {
             ElementType* vec = dataset_[indices[i]];
             for (size_t j=0; j<veclen_; ++j) {
                 mean[j] += vec[j];
index ee620dae3e838fe1bcd0ee8ccb16292a3dabe4a7..cf37bc1c6f3acdde98979fb1049f308d0b3ee8bb 100644 (file)
@@ -71,9 +71,9 @@ struct LshIndexParams : public IndexParams
 };
 
 /**
- * Randomized kd-tree index
+ * Locality-sensitive hashing  index
  *
- * Contains the k-d trees and other information for indexing a set of points
+ * Contains the tables and other information for indexing a set of points
  * for nearest-neighbor matching.
  */
 template<typename Distance>
index db8b5af946789ce7d0e20885129cb658f11045b8..8f5250171b776e880fb88f355d3bcb550fbf53b4 100644 (file)
@@ -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
index 735028fb45e553a56bd57bb9276933b0897d67c2..02f827ada0496295822287bacf39882b34623c62 100644 (file)
@@ -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;
             }