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
pull/17635/head
pemmanuelviel 5 years ago committed by GitHub
parent e45d74c8f9
commit daa88c6b9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      modules/flann/include/opencv2/flann/dist.h
  2. 5
      modules/flann/include/opencv2/flann/kmeans_index.h
  3. 4
      modules/flann/include/opencv2/flann/lsh_index.h
  4. 2
      modules/flann/include/opencv2/flann/lsh_table.h
  5. 4
      modules/flann/include/opencv2/flann/result_set.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);

@ -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];

@ -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>

@ -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

@ -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;
}

Loading…
Cancel
Save