1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge remote-tracking branch 'upstream/3.4' into merge-3.4

This commit is contained in:
Alexander Alekhin
2020-07-06 23:05:04 +00:00
28 changed files with 268 additions and 89 deletions
@@ -497,7 +497,7 @@ private:
const int nn = 1;
const size_t SAMPLE_COUNT = 1000;
assert(bestIndex_ != NULL); // must have a valid index
CV_Assert(bestIndex_ != NULL && "Requires a valid index"); // must have a valid index
float speedup = 0;
+9 -2
View File
@@ -506,7 +506,7 @@ struct Hamming2
const uint64_t* pa = reinterpret_cast<const uint64_t*>(a);
const uint64_t* pb = reinterpret_cast<const uint64_t*>(b);
ResultType result = 0;
size /= (sizeof(uint64_t)/sizeof(unsigned char));
size /= long_word_size_;
for(size_t i = 0; i < size; ++i ) {
result += popcnt64(*pa ^ *pb);
++pa;
@@ -516,7 +516,7 @@ struct Hamming2
const uint32_t* pa = reinterpret_cast<const uint32_t*>(a);
const uint32_t* pb = reinterpret_cast<const uint32_t*>(b);
ResultType result = 0;
size /= (sizeof(uint32_t)/sizeof(unsigned char));
size /= long_word_size_;
for(size_t i = 0; i < size; ++i ) {
result += popcnt32(*pa ^ *pb);
++pa;
@@ -525,6 +525,13 @@ struct Hamming2
#endif
return result;
}
private:
#ifdef FLANN_PLATFORM_64_BIT
static const size_t long_word_size_ = sizeof(uint64_t)/sizeof(unsigned char);
#else
static const size_t long_word_size_ = sizeof(uint32_t)/sizeof(unsigned char);
#endif
};
@@ -34,7 +34,6 @@
//! @cond IGNORED
#include <vector>
#include <cassert>
#include <cstdio>
#include "general.h"
@@ -35,7 +35,6 @@
#include <algorithm>
#include <map>
#include <cassert>
#include <limits>
#include <cmath>
@@ -153,7 +152,7 @@ private:
int n = indices_length;
int rnd = rand_int(n);
assert(rnd >=0 && rnd < n);
CV_DbgAssert(rnd >=0 && rnd < n);
centers[0] = dsindices[rnd];
@@ -208,7 +207,7 @@ private:
// Choose one random center and set the closestDistSq values
int index = rand_int(n);
assert(index >=0 && index < n);
CV_DbgAssert(index >=0 && index < n);
centers[0] = dsindices[index];
// Computing distance^2 will have the advantage of even higher probability further to pick new centers
@@ -295,7 +294,7 @@ private:
// Choose one random center and set the closestDistSq values
int index = rand_int(n);
assert(index >=0 && index < n);
CV_DbgAssert(index >=0 && index < n);
centers[0] = dsindices[index];
for (int i = 0; i < n; i++) {
@@ -386,7 +385,6 @@ public:
throw FLANNException("Unknown algorithm for choosing initial centers.");
}
trees_ = get_param(params,"trees",4);
root = new NodePtr[trees_];
indices = new int*[trees_];
@@ -565,10 +563,10 @@ public:
NodePtr node = branch.node;
findNN(node, result, vec, checks, maxChecks, heap, checked);
}
assert(result.full());
delete heap;
CV_Assert(result.full());
}
IndexParams getParameters() const CV_OVERRIDE
@@ -34,7 +34,6 @@
//! @cond IGNORED
#include <cstring>
#include <cassert>
#include <cmath>
#include "matrix.h"
@@ -35,7 +35,6 @@
#include <algorithm>
#include <map>
#include <cassert>
#include <cstring>
#include "general.h"
@@ -433,7 +432,7 @@ private:
if (trees_>0) {
searchLevelExact(result, vec, tree_roots_[0], 0.0, epsError);
}
assert(result.full());
CV_Assert(result.full());
}
/**
@@ -462,7 +461,7 @@ private:
delete heap;
assert(result.full());
CV_Assert(result.full());
}
@@ -35,7 +35,6 @@
#include <algorithm>
#include <map>
#include <cassert>
#include <cstring>
#include "general.h"
@@ -214,11 +213,11 @@ public:
*/
void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params) CV_OVERRIDE
{
assert(queries.cols == veclen());
assert(indices.rows >= queries.rows);
assert(dists.rows >= queries.rows);
assert(int(indices.cols) >= knn);
assert(int(dists.cols) >= knn);
CV_Assert(queries.cols == veclen());
CV_Assert(indices.rows >= queries.rows);
CV_Assert(dists.rows >= queries.rows);
CV_Assert(int(indices.cols) >= knn);
CV_Assert(int(dists.cols) >= knn);
KNNSimpleResultSet<DistanceType> resultSet(knn);
for (size_t i = 0; i < queries.rows; i++) {
@@ -35,7 +35,6 @@
#include <algorithm>
#include <map>
#include <cassert>
#include <limits>
#include <cmath>
@@ -152,7 +151,7 @@ public:
int n = indices_length;
int rnd = rand_int(n);
assert(rnd >=0 && rnd < n);
CV_DbgAssert(rnd >=0 && rnd < n);
centers[0] = indices[rnd];
@@ -207,7 +206,7 @@ public:
// Choose one random center and set the closestDistSq values
int index = rand_int(n);
assert(index >=0 && index < n);
CV_DbgAssert(index >=0 && index < n);
centers[0] = indices[index];
for (int i = 0; i < n; i++) {
@@ -502,9 +501,9 @@ public:
KMeansNodePtr node = branch.node;
findNN(node, result, vec, checks, maxChecks, heap);
}
assert(result.full());
delete heap;
CV_Assert(result.full());
}
}
@@ -663,7 +662,7 @@ private:
memset(mean,0,veclen_*sizeof(DistanceType));
for (size_t i=0; i<(size_t)indices_length; ++i) {
for (int i=0; i<indices_length; ++i) {
ElementType* vec = dataset_[indices[i]];
for (size_t j=0; j<veclen_; ++j) {
mean[j] += vec[j];
@@ -671,9 +670,9 @@ private:
variance += distance_(vec, ZeroIterator<ElementType>(), veclen_);
}
for (size_t j=0; j<veclen_; ++j) {
mean[j] /= size_;
mean[j] /= indices_length;
}
variance /= size_;
variance /= indices_length;
variance -= distance_(mean, ZeroIterator<ElementType>(), veclen_);
DistanceType tmp = 0;
@@ -726,15 +725,6 @@ private:
}
cv::AutoBuffer<double> dcenters_buf(branching*veclen_);
Matrix<double> dcenters(dcenters_buf.data(), branching, veclen_);
for (int i=0; i<centers_length; ++i) {
ElementType* vec = dataset_[centers_idx[i]];
for (size_t k=0; k<veclen_; ++k) {
dcenters[i][k] = double(vec[k]);
}
}
std::vector<DistanceType> radiuses(branching);
cv::AutoBuffer<int> count_buf(branching);
int* count = count_buf.data();
@@ -748,10 +738,10 @@ private:
int* belongs_to = belongs_to_buf.data();
for (int i=0; i<indices_length; ++i) {
DistanceType sq_dist = distance_(dataset_[indices[i]], dcenters[0], veclen_);
DistanceType sq_dist = distance_(dataset_[indices[i]], dataset_[centers_idx[0]], veclen_);
belongs_to[i] = 0;
for (int j=1; j<branching; ++j) {
DistanceType new_sq_dist = distance_(dataset_[indices[i]], dcenters[j], veclen_);
DistanceType new_sq_dist = distance_(dataset_[indices[i]], dataset_[centers_idx[j]], veclen_);
if (sq_dist>new_sq_dist) {
belongs_to[i] = j;
sq_dist = new_sq_dist;
@@ -763,6 +753,15 @@ private:
count[belongs_to[i]]++;
}
cv::AutoBuffer<double> dcenters_buf(branching*veclen_);
Matrix<double> dcenters(dcenters_buf.data(), branching, veclen_);
for (int i=0; i<centers_length; ++i) {
ElementType* vec = dataset_[centers_idx[i]];
for (size_t k=0; k<veclen_; ++k) {
dcenters[i][k] = double(vec[k]);
}
}
bool converged = false;
int iteration = 0;
while (!converged && iteration<iterations_) {
@@ -38,7 +38,6 @@
//! @cond IGNORED
#include <algorithm>
#include <cassert>
#include <cstring>
#include <map>
#include <vector>
@@ -53,6 +52,11 @@
#include "random.h"
#include "saving.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4702) //disable unreachable code
#endif
namespace cvflann
{
@@ -191,11 +195,11 @@ public:
*/
virtual void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params) CV_OVERRIDE
{
assert(queries.cols == veclen());
assert(indices.rows >= queries.rows);
assert(dists.rows >= queries.rows);
assert(int(indices.cols) >= knn);
assert(int(dists.cols) >= knn);
CV_Assert(queries.cols == veclen());
CV_Assert(indices.rows >= queries.rows);
CV_Assert(dists.rows >= queries.rows);
CV_Assert(int(indices.cols) >= knn);
CV_Assert(int(dists.cols) >= knn);
KNNUniqueResultSet<DistanceType> resultSet(knn);
@@ -391,6 +395,10 @@ private:
};
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
//! @endcond
#endif //OPENCV_FLANN_LSH_INDEX_H_
@@ -58,6 +58,12 @@
#include "dynamic_bitset.h"
#include "matrix.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4702) //disable unreachable code
#endif
namespace cvflann
{
@@ -162,8 +168,7 @@ public:
{
feature_size_ = feature_size;
CV_UNUSED(key_size);
std::cerr << "LSH is not implemented for that type" << std::endl;
assert(0);
CV_Error(cv::Error::StsUnsupportedFormat, "LSH is not implemented for that type" );
}
/** Add a feature to the table
@@ -243,8 +248,7 @@ public:
*/
size_t getKey(const ElementType* /*feature*/) const
{
std::cerr << "LSH is not implemented for that type" << std::endl;
assert(0);
CV_Error(cv::Error::StsUnsupportedFormat, "LSH is not implemented for that type" );
return 0;
}
@@ -510,6 +514,10 @@ inline LshStats LshTable<unsigned char>::getStats() const
}
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//! @endcond
@@ -69,11 +69,11 @@ public:
*/
virtual void knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, int knn, const SearchParams& params)
{
assert(queries.cols == veclen());
assert(indices.rows >= queries.rows);
assert(dists.rows >= queries.rows);
assert(int(indices.cols) >= knn);
assert(int(dists.cols) >= knn);
CV_Assert(queries.cols == veclen());
CV_Assert(indices.rows >= queries.rows);
CV_Assert(dists.rows >= queries.rows);
CV_Assert(int(indices.cols) >= knn);
CV_Assert(int(dists.cols) >= knn);
#if 0
KNNResultSet<DistanceType> resultSet(knn);
@@ -72,7 +72,7 @@ float optimizeSimplexDownhill(T* points, int n, F func, float* vals = NULL )
{
const int MAX_ITERATIONS = 10;
assert(n>0);
CV_DbgAssert(n>0);
T* p_o = new T[n];
T* p_r = new T[n];