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-06-29 21:00:18 +00:00
47 changed files with 852 additions and 719 deletions
+2 -2
View 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);
@@ -461,7 +461,7 @@ private:
DistanceType span = bbox[i].high-bbox[i].low;
if (span>(DistanceType)((1-EPS)*max_span)) {
ElementType min_elem, max_elem;
computeMinMax(ind, count, cutfeat, min_elem, max_elem);
computeMinMax(ind, count, (int)i, min_elem, max_elem);
DistanceType spread = (DistanceType)(max_elem-min_elem);
if (spread>max_spread) {
cutfeat = (int)i;
@@ -548,11 +548,19 @@ private:
/* If this is a leaf node, then do check and return. */
if ((node->child1 == NULL)&&(node->child2 == NULL)) {
DistanceType worst_dist = result_set.worstDist();
for (int i=node->left; i<node->right; ++i) {
int index = reorder_ ? i : vind_[i];
DistanceType dist = distance_(vec, data_[index], dim_, worst_dist);
if (dist<worst_dist) {
result_set.addPoint(dist,vind_[i]);
if (reorder_) {
for (int i=node->left; i<node->right; ++i) {
DistanceType dist = distance_(vec, data_[i], dim_, worst_dist);
if (dist<worst_dist) {
result_set.addPoint(dist,vind_[i]);
}
}
} else {
for (int i=node->left; i<node->right; ++i) {
DistanceType dist = distance_(vec, data_[vind_[i]], dim_, worst_dist);
if (dist<worst_dist) {
result_set.addPoint(dist,vind_[i]);
}
}
}
return;
@@ -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];
+13 -13
View File
@@ -60,20 +60,20 @@ struct LshIndexParams : public IndexParams
{
LshIndexParams(unsigned int table_number = 12, unsigned int key_size = 20, unsigned int multi_probe_level = 2)
{
(* this)["algorithm"] = FLANN_INDEX_LSH;
(*this)["algorithm"] = FLANN_INDEX_LSH;
// The number of hash tables to use
(*this)["table_number"] = table_number;
(*this)["table_number"] = static_cast<int>(table_number);
// The length of the key in the hash tables
(*this)["key_size"] = key_size;
(*this)["key_size"] = static_cast<int>(key_size);
// Number of levels to use in multi-probe (0 for standard LSH)
(*this)["multi_probe_level"] = multi_probe_level;
(*this)["multi_probe_level"] = static_cast<int>(multi_probe_level);
}
};
/**
* 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>
@@ -94,9 +94,9 @@ public:
{
// cv::flann::IndexParams sets integer params as 'int', so it is used with get_param
// in place of 'unsigned int'
table_number_ = (unsigned int)get_param<int>(index_params_,"table_number",12);
key_size_ = (unsigned int)get_param<int>(index_params_,"key_size",20);
multi_probe_level_ = (unsigned int)get_param<int>(index_params_,"multi_probe_level",2);
table_number_ = get_param(index_params_,"table_number",12);
key_size_ = get_param(index_params_,"key_size",20);
multi_probe_level_ = get_param(index_params_,"multi_probe_level",2);
feature_size_ = (unsigned)dataset_.cols;
fill_xor_mask(0, key_size_, multi_probe_level_, xor_masks_);
@@ -112,7 +112,7 @@ public:
void buildIndex() CV_OVERRIDE
{
tables_.resize(table_number_);
for (unsigned int i = 0; i < table_number_; ++i) {
for (int i = 0; i < table_number_; ++i) {
lsh::LshTable<ElementType>& table = tables_[i];
table = lsh::LshTable<ElementType>(feature_size_, key_size_);
@@ -378,11 +378,11 @@ private:
IndexParams index_params_;
/** table number */
unsigned int table_number_;
int table_number_;
/** key size */
unsigned int key_size_;
int key_size_;
/** How far should we look for neighbors in multi-probe LSH */
unsigned int multi_probe_level_;
int multi_probe_level_;
/** The XOR masks to apply to a key to get the neighboring buckets */
std::vector<lsh::BucketKey> xor_masks_;
@@ -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;
}