diff --git a/modules/flann/include/opencv2/flann/all_indices.h b/modules/flann/include/opencv2/flann/all_indices.h index 865ca53ae..898ac0998 100644 --- a/modules/flann/include/opencv2/flann/all_indices.h +++ b/modules/flann/include/opencv2/flann/all_indices.h @@ -49,19 +49,19 @@ NNIndex* create_index_by_type(const Matrix& dataset, const IndexParams& pa NNIndex* nnIndex; switch (index_type) { - case LINEAR: + case FLANN_INDEX_LINEAR: nnIndex = new LinearIndex(dataset, (const LinearIndexParams&)params); break; - case KDTREE: + case FLANN_INDEX_KDTREE: nnIndex = new KDTreeIndex(dataset, (const KDTreeIndexParams&)params); break; - case KMEANS: + case FLANN_INDEX_KMEANS: nnIndex = new KMeansIndex(dataset, (const KMeansIndexParams&)params); break; - case COMPOSITE: + case FLANN_INDEX_COMPOSITE: nnIndex = new CompositeIndex(dataset, (const CompositeIndexParams&) params); break; - case AUTOTUNED: + case FLANN_INDEX_AUTOTUNED: nnIndex = new AutotunedIndex(dataset, (const AutotunedIndexParams&) params); break; default: diff --git a/modules/flann/include/opencv2/flann/autotuned_index.h b/modules/flann/include/opencv2/flann/autotuned_index.h index 597a080ba..7a6b280fb 100644 --- a/modules/flann/include/opencv2/flann/autotuned_index.h +++ b/modules/flann/include/opencv2/flann/autotuned_index.h @@ -44,7 +44,7 @@ namespace cvflann struct AutotunedIndexParams : public IndexParams { AutotunedIndexParams( float target_precision_ = 0.8, float build_weight_ = 0.01, float memory_weight_ = 0, float sample_fraction_ = 0.1) : - IndexParams(AUTOTUNED), + IndexParams(FLANN_INDEX_AUTOTUNED), target_precision(target_precision_), build_weight(build_weight_), memory_weight(memory_weight_), @@ -55,8 +55,6 @@ struct AutotunedIndexParams : public IndexParams { float memory_weight; // index memory weighting factor float sample_fraction; // what fraction of the dataset to use for autotuning - flann_algorithm_t getIndexType() const { return algorithm; } - void print() const { logger().info("Index type: %d\n",(int)algorithm); @@ -123,13 +121,13 @@ public: logger().info("----------------------------------------------------\n"); flann_algorithm_t index_type = bestParams->getIndexType(); switch (index_type) { - case LINEAR: + case FLANN_INDEX_LINEAR: bestIndex = new LinearIndex(dataset, (const LinearIndexParams&)*bestParams); break; - case KDTREE: + case FLANN_INDEX_KDTREE: bestIndex = new KDTreeIndex(dataset, (const KDTreeIndexParams&)*bestParams); break; - case KMEANS: + case FLANN_INDEX_KMEANS: bestIndex = new KMeansIndex(dataset, (const KMeansIndexParams&)*bestParams); break; default: @@ -211,7 +209,7 @@ public: */ virtual flann_algorithm_t getType() const { - return AUTOTUNED; + return FLANN_INDEX_AUTOTUNED; } private: @@ -347,7 +345,7 @@ private: for (size_t i=0; igetType() == KMEANS) { + if (bestIndex->getType() == FLANN_INDEX_KMEANS) { logger().info("KMeans algorithm, estimating cluster border factor\n"); KMeansIndex* kmeans = (KMeansIndex*)bestIndex; float bestSearchTime = -1; diff --git a/modules/flann/include/opencv2/flann/composite_index.h b/modules/flann/include/opencv2/flann/composite_index.h index dfcfab515..4d2bfce81 100644 --- a/modules/flann/include/opencv2/flann/composite_index.h +++ b/modules/flann/include/opencv2/flann/composite_index.h @@ -40,8 +40,8 @@ namespace cvflann struct CompositeIndexParams : public IndexParams { CompositeIndexParams(int trees_ = 4, int branching_ = 32, int iterations_ = 11, - flann_centers_init_t centers_init_ = CENTERS_RANDOM, float cb_index_ = 0.2 ) : - IndexParams(COMPOSITE), + flann_centers_init_t centers_init_ = FLANN_CENTERS_RANDOM, float cb_index_ = 0.2 ) : + IndexParams(FLANN_INDEX_COMPOSITE), trees(trees_), branching(branching_), iterations(iterations_), @@ -54,8 +54,6 @@ struct CompositeIndexParams : public IndexParams { flann_centers_init_t centers_init; // algorithm used for picking the initial cluster centers for kmeans tree float cb_index; // cluster boundary index. Used when searching the kmeans tree - flann_algorithm_t getIndexType() const { return algorithm; } - void print() const { logger().info("Index type: %d\n",(int)algorithm); @@ -102,7 +100,7 @@ public: flann_algorithm_t getType() const { - return COMPOSITE; + return FLANN_INDEX_COMPOSITE; } diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h index b10a01a7b..2ddbee31e 100644 --- a/modules/flann/include/opencv2/flann/dist.h +++ b/modules/flann/include/opencv2/flann/dist.h @@ -304,21 +304,21 @@ template double custom_dist(Iterator1 first1, Iterator1 last1, Iterator2 first2, double acc = 0) { switch (flann_distance_type()) { - case EUCLIDEAN: + case FLANN_DIST_EUCLIDEAN: return euclidean_dist(first1, last1, first2, acc); - case MANHATTAN: + case FLANN_DIST_MANHATTAN: return manhattan_dist(first1, last1, first2, acc); - case MINKOWSKI: + case FLANN_DIST_MINKOWSKI: return minkowski_dist(first1, last1, first2, acc); - case MAX_DIST: + case FLANN_DIST_MAX: return max_dist(first1, last1, first2, acc); - case HIK: + case FLANN_DIST_HIST_INTERSECT: return hist_intersection_dist_sq(first1, last1, first2, acc); - case HELLINGER: + case FLANN_DIST_HELLINGER: return hellinger_dist(first1, last1, first2, acc); - case CS: + case FLANN_DIST_CS: return chi_square_dist(first1, last1, first2, acc); - case KL: + case FLANN_DIST_KL: return kl_divergence(first1, last1, first2, acc); default: return euclidean_dist(first1, last1, first2, acc); diff --git a/modules/flann/include/opencv2/flann/flann_base.hpp b/modules/flann/include/opencv2/flann/flann_base.hpp index 227f94501..46143df26 100644 --- a/modules/flann/include/opencv2/flann/flann_base.hpp +++ b/modules/flann/include/opencv2/flann/flann_base.hpp @@ -67,12 +67,10 @@ CV_EXPORTS void set_distance_type(flann_distance_t distance_type, int order); struct CV_EXPORTS SavedIndexParams : public IndexParams { - SavedIndexParams(std::string filename_) : IndexParams(SAVED), filename(filename_) {} + SavedIndexParams(std::string filename_) : IndexParams(FLANN_INDEX_SAVED), filename(filename_) {} std::string filename; // filename of the stored index - flann_algorithm_t getIndexType() const { return algorithm; } - void print() const { logger().info("Index type: %d\n",(int)algorithm); @@ -138,7 +136,7 @@ Index::Index(const Matrix& dataset, const IndexParams& params) flann_algorithm_t index_type = params.getIndexType(); built = false; - if (index_type==SAVED) { + if (index_type==FLANN_INDEX_SAVED) { nnIndex = load_saved_index(dataset, ((const SavedIndexParams&)params).filename); built = true; } diff --git a/modules/flann/include/opencv2/flann/general.h b/modules/flann/include/opencv2/flann/general.h index be879a9ff..7ca25cd9a 100644 --- a/modules/flann/include/opencv2/flann/general.h +++ b/modules/flann/include/opencv2/flann/general.h @@ -44,18 +44,18 @@ namespace cvflann { /* Nearest neighbour index algorithms */ enum flann_algorithm_t { - LINEAR = 0, - KDTREE = 1, - KMEANS = 2, - COMPOSITE = 3, - SAVED = 254, - AUTOTUNED = 255 + FLANN_INDEX_LINEAR = 0, + FLANN_INDEX_KDTREE = 1, + FLANN_INDEX_KMEANS = 2, + FLANN_INDEX_COMPOSITE = 3, + FLANN_INDEX_SAVED = 254, + FLANN_INDEX_AUTOTUNED = 255 }; enum flann_centers_init_t { - CENTERS_RANDOM = 0, - CENTERS_GONZALES = 1, - CENTERS_KMEANSPP = 2 + FLANN_CENTERS_RANDOM = 0, + FLANN_CENTERS_GONZALES = 1, + FLANN_CENTERS_KMEANSPP = 2 }; enum flann_log_level_t { @@ -67,29 +67,31 @@ enum flann_log_level_t { }; enum flann_distance_t { - EUCLIDEAN = 1, - MANHATTAN = 2, - MINKOWSKI = 3, - MAX_DIST = 4, - HIK = 5, - HELLINGER = 6, - CS = 7, - CHI_SQUARE = 7, - KL = 8, - KULLBACK_LEIBLER = 8 + FLANN_DIST_EUCLIDEAN = 1, + FLANN_DIST_L2 = 1, + FLANN_DIST_MANHATTAN = 2, + FLANN_DIST_L1 = 2, + FLANN_DIST_MINKOWSKI = 3, + FLANN_DIST_MAX = 4, + FLANN_DIST_HIST_INTERSECT = 5, + FLANN_DIST_HELLINGER = 6, + FLANN_DIST_CHI_SQUARE = 7, + FLANN_DIST_CS = 7, + FLANN_DIST_KULLBACK_LEIBLER = 8, + FLANN_DIST_KL = 8 }; enum flann_datatype_t { - INT8 = 0, - INT16 = 1, - INT32 = 2, - INT64 = 3, - UINT8 = 4, - UINT16 = 5, - UINT32 = 6, - UINT64 = 7, - FLOAT32 = 8, - FLOAT64 = 9 + FLANN_INT8 = 0, + FLANN_INT16 = 1, + FLANN_INT32 = 2, + FLANN_INT64 = 3, + FLANN_UINT8 = 4, + FLANN_UINT16 = 5, + FLANN_UINT32 = 6, + FLANN_UINT64 = 7, + FLANN_FLOAT32 = 8, + FLANN_FLOAT64 = 9 }; template @@ -125,7 +127,7 @@ protected: public: virtual ~IndexParams() {} - virtual flann_algorithm_t getIndexType() const = 0; + virtual flann_algorithm_t getIndexType() const { return algorithm; } virtual void print() const = 0; diff --git a/modules/flann/include/opencv2/flann/kdtree_index.h b/modules/flann/include/opencv2/flann/kdtree_index.h index bf485d33f..ffcbb4625 100644 --- a/modules/flann/include/opencv2/flann/kdtree_index.h +++ b/modules/flann/include/opencv2/flann/kdtree_index.h @@ -50,12 +50,10 @@ namespace cvflann { struct CV_EXPORTS KDTreeIndexParams : public IndexParams { - KDTreeIndexParams(int trees_ = 4) : IndexParams(KDTREE), trees(trees_) {}; + KDTreeIndexParams(int trees_ = 4) : IndexParams(FLANN_INDEX_KDTREE), trees(trees_) {}; int trees; // number of randomized trees to use (for kdtree) - flann_algorithm_t getIndexType() const { return algorithm; } - void print() const { logger().info("Index type: %d\n",(int)algorithm); @@ -167,7 +165,7 @@ public: flann_algorithm_t getType() const { - return KDTREE; + return FLANN_INDEX_KDTREE; } /** diff --git a/modules/flann/include/opencv2/flann/kmeans_index.h b/modules/flann/include/opencv2/flann/kmeans_index.h index a0a1d6626..6c688d808 100644 --- a/modules/flann/include/opencv2/flann/kmeans_index.h +++ b/modules/flann/include/opencv2/flann/kmeans_index.h @@ -52,8 +52,8 @@ namespace cvflann struct CV_EXPORTS KMeansIndexParams : public IndexParams { KMeansIndexParams(int branching_ = 32, int iterations_ = 11, - flann_centers_init_t centers_init_ = CENTERS_RANDOM, float cb_index_ = 0.2 ) : - IndexParams(KMEANS), + flann_centers_init_t centers_init_ = FLANN_CENTERS_RANDOM, float cb_index_ = 0.2 ) : + IndexParams(FLANN_INDEX_KMEANS), branching(branching_), iterations(iterations_), centers_init(centers_init_), @@ -64,8 +64,6 @@ struct CV_EXPORTS KMeansIndexParams : public IndexParams { flann_centers_init_t centers_init; // algorithm used for picking the initial cluster centers for kmeans tree float cb_index; // cluster boundary index. Used when searching the kmeans tree - flann_algorithm_t getIndexType() const { return KMEANS; } - void print() const { logger().info("Index type: %d\n",(int)algorithm); @@ -379,7 +377,7 @@ public: flann_algorithm_t getType() const { - return KMEANS; + return FLANN_INDEX_KMEANS; } /** @@ -404,13 +402,13 @@ public: } flann_centers_init_t centersInit = params.centers_init; - if (centersInit==CENTERS_RANDOM) { + if (centersInit==FLANN_CENTERS_RANDOM) { chooseCenters = &KMeansIndex::chooseCentersRandom; } - else if (centersInit==CENTERS_GONZALES) { + else if (centersInit==FLANN_CENTERS_GONZALES) { chooseCenters = &KMeansIndex::chooseCentersGonzales; } - else if (centersInit==CENTERS_KMEANSPP) { + else if (centersInit==FLANN_CENTERS_KMEANSPP) { chooseCenters = &KMeansIndex::chooseCentersKMeanspp; } else { diff --git a/modules/flann/include/opencv2/flann/linear_index.h b/modules/flann/include/opencv2/flann/linear_index.h index de7c51c3f..c24cc0643 100644 --- a/modules/flann/include/opencv2/flann/linear_index.h +++ b/modules/flann/include/opencv2/flann/linear_index.h @@ -39,9 +39,7 @@ namespace cvflann { struct CV_EXPORTS LinearIndexParams : public IndexParams { - LinearIndexParams() : IndexParams(LINEAR) {}; - - flann_algorithm_t getIndexType() const { return algorithm; } + LinearIndexParams() : IndexParams(FLANN_INDEX_LINEAR) {}; void print() const { @@ -65,7 +63,7 @@ public: flann_algorithm_t getType() const { - return LINEAR; + return FLANN_INDEX_LINEAR; } diff --git a/modules/flann/include/opencv2/flann/saving.h b/modules/flann/include/opencv2/flann/saving.h index bc75eb509..52116ec96 100644 --- a/modules/flann/include/opencv2/flann/saving.h +++ b/modules/flann/include/opencv2/flann/saving.h @@ -37,14 +37,14 @@ namespace cvflann { template struct Datatype {}; -template<> struct Datatype { static flann_datatype_t type() { return INT8; } }; -template<> struct Datatype { static flann_datatype_t type() { return INT16; } }; -template<> struct Datatype { static flann_datatype_t type() { return INT32; } }; -template<> struct Datatype { static flann_datatype_t type() { return UINT8; } }; -template<> struct Datatype { static flann_datatype_t type() { return UINT16; } }; -template<> struct Datatype { static flann_datatype_t type() { return UINT32; } }; -template<> struct Datatype { static flann_datatype_t type() { return FLOAT32; } }; -template<> struct Datatype { static flann_datatype_t type() { return FLOAT64; } }; +template<> struct Datatype { static flann_datatype_t type() { return FLANN_INT8; } }; +template<> struct Datatype { static flann_datatype_t type() { return FLANN_INT16; } }; +template<> struct Datatype { static flann_datatype_t type() { return FLANN_INT32; } }; +template<> struct Datatype { static flann_datatype_t type() { return FLANN_UINT8; } }; +template<> struct Datatype { static flann_datatype_t type() { return FLANN_UINT16; } }; +template<> struct Datatype { static flann_datatype_t type() { return FLANN_UINT32; } }; +template<> struct Datatype { static flann_datatype_t type() { return FLANN_FLOAT32; } }; +template<> struct Datatype { static flann_datatype_t type() { return FLANN_FLOAT64; } }; CV_EXPORTS const char* FLANN_SIGNATURE(); diff --git a/modules/flann/src/flann.cpp b/modules/flann/src/flann.cpp index 3742381ef..30a82ea6f 100644 --- a/modules/flann/src/flann.cpp +++ b/modules/flann/src/flann.cpp @@ -35,7 +35,7 @@ namespace cvflann /** Global variable indicating the distance metric * to be used. */ -flann_distance_t flann_distance_type_ = EUCLIDEAN; +flann_distance_t flann_distance_type_ = FLANN_DIST_EUCLIDEAN; flann_distance_t flann_distance_type() { return flann_distance_type_; } /** @@ -208,12 +208,12 @@ class StaticInit public: StaticInit() { - ParamsFactory_instance().register_(LINEAR); - ParamsFactory_instance().register_(KDTREE); - ParamsFactory_instance().register_(KMEANS); - ParamsFactory_instance().register_(COMPOSITE); - ParamsFactory_instance().register_(AUTOTUNED); -// ParamsFactory::instance().register_(SAVED); + ParamsFactory_instance().register_(FLANN_INDEX_LINEAR); + ParamsFactory_instance().register_(FLANN_INDEX_KDTREE); + ParamsFactory_instance().register_(FLANN_INDEX_KMEANS); + ParamsFactory_instance().register_(FLANN_INDEX_COMPOSITE); + ParamsFactory_instance().register_(FLANN_INDEX_AUTOTUNED); +// ParamsFactory::instance().register_(FLANN_INDEX_SAVED); } }; StaticInit __init;