From f678c8f07bb9d67a98585060ed43121b31912b09 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Fri, 15 Oct 2010 18:57:59 +0000 Subject: [PATCH] made FLANN (and dependent on it code) build fine on Windows. Most of the changes are added CV_EXPORTS' into the class declarations and extern variables are turned into external functions (as a nice side effect the variables are now read-only) --- .../flann/include/opencv2/flann/allocator.h | 2 +- .../include/opencv2/flann/autotuned_index.h | 54 +++++++++---------- .../include/opencv2/flann/composite_index.h | 16 +++--- modules/flann/include/opencv2/flann/dist.h | 13 ++--- modules/flann/include/opencv2/flann/flann.hpp | 2 +- .../include/opencv2/flann/flann_base.hpp | 18 +++---- modules/flann/include/opencv2/flann/general.h | 24 ++++----- .../include/opencv2/flann/index_testing.h | 34 ++++++------ .../include/opencv2/flann/kdtree_index.h | 6 +-- .../include/opencv2/flann/kmeans_index.h | 22 ++++---- .../include/opencv2/flann/linear_index.h | 4 +- modules/flann/include/opencv2/flann/logger.h | 4 +- .../include/opencv2/flann/object_factory.h | 1 + modules/flann/include/opencv2/flann/random.h | 8 +-- .../flann/include/opencv2/flann/result_set.h | 2 +- modules/flann/include/opencv2/flann/saving.h | 14 ++--- .../include/opencv2/flann/simplex_downhill.h | 10 ++-- modules/flann/include/opencv2/flann/timer.h | 2 +- modules/flann/src/flann.cpp | 45 +++++++--------- modules/flann/src/precomp.cpp | 1 + modules/flann/src/precomp.hpp | 18 +++++++ modules/objdetect/src/_lsvm_error.h | 6 +-- samples/c/find_obj.cpp | 2 +- 23 files changed, 160 insertions(+), 148 deletions(-) create mode 100644 modules/flann/src/precomp.cpp diff --git a/modules/flann/include/opencv2/flann/allocator.h b/modules/flann/include/opencv2/flann/allocator.h index a7e357e370..fca88d681d 100644 --- a/modules/flann/include/opencv2/flann/allocator.h +++ b/modules/flann/include/opencv2/flann/allocator.h @@ -70,7 +70,7 @@ T* allocate(size_t count = 1) const size_t WORDSIZE=16; const size_t BLOCKSIZE=8192; -class PooledAllocator +class CV_EXPORTS PooledAllocator { /* We maintain memory alignment to word boundaries by requiring that all allocations be in multiples of the machine wordsize. */ diff --git a/modules/flann/include/opencv2/flann/autotuned_index.h b/modules/flann/include/opencv2/flann/autotuned_index.h index d7e8a71118..0d32e398fc 100644 --- a/modules/flann/include/opencv2/flann/autotuned_index.h +++ b/modules/flann/include/opencv2/flann/autotuned_index.h @@ -59,11 +59,11 @@ struct AutotunedIndexParams : public IndexParams { void print() const { - logger.info("Index type: %d\n",(int)algorithm); - logger.info("Target precision: %g\n", target_precision); - logger.info("Build weight: %g\n", build_weight); - logger.info("Memory weight: %g\n", memory_weight); - logger.info("Sample fraction: %g\n", sample_fraction); + logger().info("Index type: %d\n",(int)algorithm); + logger().info("logger(). precision: %g\n", target_precision); + logger().info("Build weight: %g\n", build_weight); + logger().info("Memory weight: %g\n", memory_weight); + logger().info("Sample fraction: %g\n", sample_fraction); } }; @@ -117,10 +117,10 @@ public: virtual void buildIndex() { bestParams = estimateBuildParams(); - logger.info("----------------------------------------------------\n"); - logger.info("Autotuned parameters:\n"); + logger().info("----------------------------------------------------\n"); + logger().info("Autotuned parameters:\n"); bestParams->print(); - logger.info("----------------------------------------------------\n"); + logger().info("----------------------------------------------------\n"); flann_algorithm_t index_type = bestParams->getIndexType(); switch (index_type) { case LINEAR: @@ -234,7 +234,7 @@ private: int checks; const int nn = 1; - logger.info("KMeansTree using params: max_iterations=%d, branching=%d\n", kmeans_params.iterations, kmeans_params.branching); + logger().info("KMeansTree using params: max_iterations=%d, branching=%d\n", kmeans_params.iterations, kmeans_params.branching); KMeansIndex kmeans(sampledDataset, kmeans_params); // measure index build time t.start(); @@ -250,7 +250,7 @@ private: cost.searchTimeCost = searchTime; cost.buildTimeCost = buildTime; cost.timeCost = (buildTime*index_params.build_weight+searchTime); - logger.info("KMeansTree buildTime=%g, searchTime=%g, timeCost=%g, buildTimeFactor=%g\n",buildTime, searchTime, cost.timeCost, index_params.build_weight); + logger().info("KMeansTree buildTime=%g, searchTime=%g, timeCost=%g, buildTimeFactor=%g\n",buildTime, searchTime, cost.timeCost, index_params.build_weight); } @@ -260,7 +260,7 @@ private: int checks; const int nn = 1; - logger.info("KDTree using params: trees=%d\n",kdtree_params.trees); + logger().info("KDTree using params: trees=%d\n",kdtree_params.trees); KDTreeIndex kdtree(sampledDataset, kdtree_params); t.start(); @@ -276,7 +276,7 @@ private: cost.searchTimeCost = searchTime; cost.buildTimeCost = buildTime; cost.timeCost = (buildTime*index_params.build_weight+searchTime); - logger.info("KDTree buildTime=%g, searchTime=%g, timeCost=%g\n",buildTime, searchTime, cost.timeCost); + logger().info("KDTree buildTime=%g, searchTime=%g, timeCost=%g\n",buildTime, searchTime, cost.timeCost); } @@ -330,7 +330,7 @@ private: KMeansCostData optimizeKMeans() { - logger.info("KMEANS, Step 1: Exploring parameter space\n"); + logger().info("KMEANS, Step 1: Exploring parameter space\n"); // explore kmeans parameters space using combinations of the parameters below int maxIterations[] = { 1, 5, 10, 15 }; @@ -363,7 +363,7 @@ private: } } -// logger.info("KMEANS, Step 2: simplex-downhill optimization\n"); +// logger().info("KMEANS, Step 2: simplex-downhill optimization\n"); // // const int n = 2; // // choose initial simplex points as the best parameters so far @@ -397,7 +397,7 @@ private: } // display the costs obtained for (int i=0;i(new int[testDataset.rows],testDataset.rows, 1); StartStopTimer t; t.start(); @@ -511,7 +511,7 @@ private: IndexParams* bestParams = new LinearIndexParams(); // Start parameter autotune process - logger.info("Autotuning parameters...\n"); + logger().info("Autotuning parameters...\n"); KMeansCostData kmeansCost = optimizeKMeans(); @@ -554,7 +554,7 @@ private: if (samples>0) { Matrix testDataset = random_sample(dataset,samples); - logger.info("Computing ground truth\n"); + logger().info("Computing ground truth\n"); // we need to compute the ground truth first Matrix gt_matches(new int[testDataset.rows],testDataset.rows,1); @@ -565,12 +565,12 @@ private: float linear = t.value; int checks; - logger.info("Estimating number of checks\n"); + logger().info("Estimating number of checks\n"); float searchTime; float cb_index; if (bestIndex->getType() == KMEANS) { - logger.info("KMeans algorithm, estimating cluster border factor\n"); + logger().info("KMeans algorithm, estimating cluster border factor\n"); KMeansIndex* kmeans = (KMeansIndex*)bestIndex; float bestSearchTime = -1; float best_cb_index = -1; @@ -589,14 +589,14 @@ private: checks = best_checks; kmeans->set_cb_index(best_cb_index); - logger.info("Optimum cb_index: %g\n",cb_index); + logger().info("Optimum cb_index: %g\n",cb_index); ((KMeansIndexParams*)bestParams)->cb_index = cb_index; } else { searchTime = test_index_precision(*bestIndex, dataset, testDataset, gt_matches, index_params.target_precision, checks, nn, 1); } - logger.info("Required number of checks: %d \n",checks);; + logger().info("Required number of checks: %d \n",checks);; searchParams.checks = checks; speedup = linear/searchTime; diff --git a/modules/flann/include/opencv2/flann/composite_index.h b/modules/flann/include/opencv2/flann/composite_index.h index d3eccd1e37..24bc640558 100644 --- a/modules/flann/include/opencv2/flann/composite_index.h +++ b/modules/flann/include/opencv2/flann/composite_index.h @@ -58,12 +58,12 @@ struct CompositeIndexParams : public IndexParams { void print() const { - logger.info("Index type: %d\n",(int)algorithm); - logger.info("Trees: %d\n", trees); - logger.info("Branching: %d\n", branching); - logger.info("Iterations: %d\n", iterations); - logger.info("Centres initialisation: %d\n", centers_init); - logger.info("Cluster boundary weight: %g\n", cb_index); + logger().info("Index type: %d\n",(int)algorithm); + logger().info("Trees: %d\n", trees); + logger().info("Branching: %d\n", branching); + logger().info("Iterations: %d\n", iterations); + logger().info("Centres initialisation: %d\n", centers_init); + logger().info("Cluster boundary weight: %g\n", cb_index); } }; @@ -124,9 +124,9 @@ public: void buildIndex() { - logger.info("Building kmeans tree...\n"); + logger().info("Building kmeans tree...\n"); kmeans->buildIndex(); - logger.info("Building kdtree tree...\n"); + logger().info("Building kdtree tree...\n"); kdtree->buildIndex(); } diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h index 5de56e565b..162d89bab8 100644 --- a/modules/flann/include/opencv2/flann/dist.h +++ b/modules/flann/include/opencv2/flann/dist.h @@ -82,7 +82,7 @@ double euclidean_dist(Iterator1 first1, Iterator1 last1, Iterator2 first2, doubl return distsq; } -double euclidean_dist(const unsigned char* first1, const unsigned char* last1, unsigned char* first2, double acc); +CV_EXPORTS double euclidean_dist(const unsigned char* first1, const unsigned char* last1, unsigned char* first2, double acc); /** @@ -117,7 +117,7 @@ double manhattan_dist(Iterator1 first1, Iterator1 last1, Iterator2 first2, doubl } -extern int flann_minkowski_order; +CV_EXPORTS int flann_minkowski_order(); /** * Compute the Minkowski (L_p) distance between two vectors. * @@ -134,7 +134,7 @@ double minkowski_dist(Iterator1 first1, Iterator1 last1, Iterator2 first2, doubl double diff0, diff1, diff2, diff3; Iterator1 lastgroup = last1 - 3; - int p = flann_minkowski_order; + int p = flann_minkowski_order(); /* Process 4 items with each loop for efficiency. */ while (first1 < lastgroup) { @@ -293,7 +293,7 @@ double kl_divergence(Iterator1 first1, Iterator1 last1, Iterator2 first2, double -extern flann_distance_t flann_distance_type; +CV_EXPORTS flann_distance_t flann_distance_type(); /** * Custom distance function. The distance computed is dependent on the value * of the 'flann_distance_type' global variable. @@ -304,7 +304,7 @@ extern flann_distance_t flann_distance_type; template double custom_dist(Iterator1 first1, Iterator1 last1, Iterator2 first2, double acc = 0) { - switch (flann_distance_type) { + switch (flann_distance_type()) { case EUCLIDEAN: return euclidean_dist(first1, last1, first2, acc); case MANHATTAN: @@ -353,7 +353,8 @@ struct ZeroIterator { } }; -extern ZeroIterator zero; + +CV_EXPORTS ZeroIterator& zero(); } // namespace cvflann diff --git a/modules/flann/include/opencv2/flann/flann.hpp b/modules/flann/include/opencv2/flann/flann.hpp index 15484c8a68..e3a05204a9 100644 --- a/modules/flann/include/opencv2/flann/flann.hpp +++ b/modules/flann/include/opencv2/flann/flann.hpp @@ -74,7 +74,7 @@ using ::cvflann::SearchParams; template -class Index_ { +class CV_EXPORTS Index_ { ::cvflann::Index* nnIndex; public: diff --git a/modules/flann/include/opencv2/flann/flann_base.hpp b/modules/flann/include/opencv2/flann/flann_base.hpp index 5e85f7982e..2189e46ecb 100644 --- a/modules/flann/include/opencv2/flann/flann_base.hpp +++ b/modules/flann/include/opencv2/flann/flann_base.hpp @@ -55,7 +55,7 @@ Sets the log level used for all flann functions Params: level = verbosity level */ -void log_verbosity(int level); +CV_EXPORTS void log_verbosity(int level); /** @@ -63,10 +63,10 @@ void log_verbosity(int level); * If distance type specified is MINKOWSKI, the second argument * specifies which order the minkowski distance should have. */ -void set_distance_type(flann_distance_t distance_type, int order); +CV_EXPORTS void set_distance_type(flann_distance_t distance_type, int order); -struct SavedIndexParams : public IndexParams { +struct CV_EXPORTS SavedIndexParams : public IndexParams { SavedIndexParams(std::string filename_) : IndexParams(SAVED), filename(filename_) {} std::string filename; // filename of the stored index @@ -75,13 +75,13 @@ struct SavedIndexParams : public IndexParams { void print() const { - logger.info("Index type: %d\n",(int)algorithm); - logger.info("Filename: %s\n", filename.c_str()); + logger().info("Index type: %d\n",(int)algorithm); + logger().info("Filename: %s\n", filename.c_str()); } }; template -class Index { +class CV_EXPORTS Index { NNIndex* nnIndex; bool built; @@ -178,7 +178,7 @@ void Index::knnSearch(const Matrix& queries, Matrix& indices, Matrix< for (size_t i = 0; i < queries.rows; i++) { T* target = queries[i]; - resultSet.init(target, queries.cols); + resultSet.init(target, (int)queries.cols); nnIndex->findNeighbors(resultSet, target, searchParams); @@ -202,7 +202,7 @@ int Index::radiusSearch(const Matrix& query, Matrix& indices, Matrix< assert(query.cols==nnIndex->veclen()); RadiusResultSet resultSet(radius); - resultSet.init(query.data, query.cols); + resultSet.init(query.data, (int)query.cols); nnIndex->findNeighbors(resultSet,query.data,searchParams); // TODO: optimise here @@ -217,7 +217,7 @@ int Index::radiusSearch(const Matrix& query, Matrix& indices, Matrix< dists[0][i] = distances[i]; } - return count_nn; + return (int)count_nn; } diff --git a/modules/flann/include/opencv2/flann/general.h b/modules/flann/include/opencv2/flann/general.h index b75e5293c3..fcdff5013e 100644 --- a/modules/flann/include/opencv2/flann/general.h +++ b/modules/flann/include/opencv2/flann/general.h @@ -31,9 +31,16 @@ #ifndef CONSTANTS_H #define CONSTANTS_H -#define ARRAY_LEN(a) (sizeof(a)/sizeof(a[0])) +#ifdef __cplusplus + +#include +#include +#include "opencv2/flann/object_factory.h" +namespace cvflann { +#undef ARRAY_LEN +#define ARRAY_LEN(a) (sizeof(a)/sizeof(a[0])) /* Nearest neighbour index algorithms */ enum flann_algorithm_t { @@ -85,17 +92,6 @@ enum flann_datatype_t { FLOAT64 = 9 }; - - -#ifdef __cplusplus - -#include -#include -#include "opencv2/flann/object_factory.h" - -namespace cvflann { - - template struct DistType { @@ -123,7 +119,7 @@ class FLANNException : public std::runtime_error { }; -struct IndexParams { +struct CV_EXPORTS IndexParams { protected: IndexParams(flann_algorithm_t algorithm_) : algorithm(algorithm_) {}; @@ -139,7 +135,7 @@ public: typedef ObjectFactory ParamsFactory; -struct SearchParams { +struct CV_EXPORTS SearchParams { SearchParams(int checks_ = 32) : checks(checks_) {}; diff --git a/modules/flann/include/opencv2/flann/index_testing.h b/modules/flann/include/opencv2/flann/index_testing.h index 40a957fc2f..04163f2b9d 100644 --- a/modules/flann/include/opencv2/flann/index_testing.h +++ b/modules/flann/include/opencv2/flann/index_testing.h @@ -46,7 +46,7 @@ using namespace std; namespace cvflann { -int countCorrectMatches(int* neighbors, int* groundTruth, int n); +CV_EXPORTS int countCorrectMatches(int* neighbors, int* groundTruth, int n); template @@ -73,7 +73,7 @@ template float search_with_ground_truth(NNIndex& index, const Matrix& inputData, const Matrix& testData, const Matrix& matches, int nn, int checks, float& time, float& dist, int skipMatches) { if (matches.cols& index, const Matrix float test_index_checks(NNIndex& index, const Matrix& inputData, const Matrix& testData, const Matrix& matches, int checks, float& precision, int nn = 1, int skipMatches = 0) { - logger.info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); - logger.info("---------------------------------------------------------\n"); + logger().info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); + logger().info("---------------------------------------------------------\n"); float time = 0; float dist = 0; @@ -136,8 +136,8 @@ float test_index_precision(NNIndex& index, const Matrix& i { const float SEARCH_EPS = 0.001; - logger.info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); - logger.info("---------------------------------------------------------\n"); + logger().info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n"); + logger().info("---------------------------------------------------------\n"); int c2 = 1; float p2; @@ -149,7 +149,7 @@ float test_index_precision(NNIndex& index, const Matrix& i p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, skipMatches); if (p2>precision) { - logger.info("Got as close as I can\n"); + logger().info("Got as close as I can\n"); checks = c2; return time; } @@ -164,7 +164,7 @@ float test_index_precision(NNIndex& index, const Matrix& i int cx; float realPrecision; if (fabs(p2-precision)>SEARCH_EPS) { - logger.info("Start linear estimation\n"); + logger().info("Start linear estimation\n"); // after we got to values in the vecinity of the desired precision // use linear approximation get a better estimation @@ -180,7 +180,7 @@ float test_index_precision(NNIndex& index, const Matrix& i } cx = (c1+c2)/2; if (cx==c1) { - logger.info("Got as close as I can\n"); + logger().info("Got as close as I can\n"); break; } realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, skipMatches); @@ -190,7 +190,7 @@ float test_index_precision(NNIndex& index, const Matrix& i p2 = realPrecision; } else { - logger.info("No need for linear estimation\n"); + logger().info("No need for linear estimation\n"); cx = c2; realPrecision = p2; } @@ -212,8 +212,8 @@ float test_index_precisions(NNIndex& index, const Matrix& int pindex = 0; float precision = precisions[pindex]; - logger.info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist"); - logger.info("---------------------------------------------------------"); + logger().info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist"); + logger().info("---------------------------------------------------------"); int c2 = 1; float p2; @@ -234,7 +234,7 @@ float test_index_precisions(NNIndex& index, const Matrix& } if (pindex==precisions_length) { - logger.info("Got as close as I can\n"); + logger().info("Got as close as I can\n"); return time; } @@ -252,7 +252,7 @@ float test_index_precisions(NNIndex& index, const Matrix& int cx; float realPrecision; if (fabs(p2-precision)>SEARCH_EPS) { - logger.info("Start linear estimation\n"); + logger().info("Start linear estimation\n"); // after we got to values in the vecinity of the desired precision // use linear approximation get a better estimation @@ -268,7 +268,7 @@ float test_index_precisions(NNIndex& index, const Matrix& } cx = (c1+c2)/2; if (cx==c1) { - logger.info("Got as close as I can\n"); + logger().info("Got as close as I can\n"); break; } realPrecision = search_with_ground_truth(index, inputData, testData, matches, nn, cx, time, dist, skipMatches); @@ -278,7 +278,7 @@ float test_index_precisions(NNIndex& index, const Matrix& p2 = realPrecision; } else { - logger.info("No need for linear estimation\n"); + logger().info("No need for linear estimation\n"); cx = c2; realPrecision = p2; } diff --git a/modules/flann/include/opencv2/flann/kdtree_index.h b/modules/flann/include/opencv2/flann/kdtree_index.h index 3286f02f28..58fc2ce71b 100644 --- a/modules/flann/include/opencv2/flann/kdtree_index.h +++ b/modules/flann/include/opencv2/flann/kdtree_index.h @@ -51,7 +51,7 @@ using namespace std; namespace cvflann { -struct KDTreeIndexParams : public IndexParams { +struct CV_EXPORTS KDTreeIndexParams : public IndexParams { KDTreeIndexParams(int trees_ = 4) : IndexParams(KDTREE), trees(trees_) {}; int trees; // number of randomized trees to use (for kdtree) @@ -60,8 +60,8 @@ struct KDTreeIndexParams : public IndexParams { void print() const { - logger.info("Index type: %d\n",(int)algorithm); - logger.info("Trees: %d\n", trees); + logger().info("Index type: %d\n",(int)algorithm); + logger().info("Trees: %d\n", trees); } }; diff --git a/modules/flann/include/opencv2/flann/kmeans_index.h b/modules/flann/include/opencv2/flann/kmeans_index.h index dc519e5066..6ed4dac51e 100644 --- a/modules/flann/include/opencv2/flann/kmeans_index.h +++ b/modules/flann/include/opencv2/flann/kmeans_index.h @@ -52,7 +52,7 @@ namespace cvflann { -struct KMeansIndexParams : public IndexParams { +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), @@ -70,11 +70,11 @@ struct KMeansIndexParams : public IndexParams { void print() const { - logger.info("Index type: %d\n",(int)algorithm); - logger.info("Branching: %d\n", branching); - logger.info("Iterations: %d\n", iterations); - logger.info("Centres initialisation: %d\n", centers_init); - logger.info("Cluster boundary weight: %g\n", cb_index); + logger().info("Index type: %d\n",(int)algorithm); + logger().info("Branching: %d\n", branching); + logger().info("Iterations: %d\n", iterations); + logger().info("Centres initialisation: %d\n", centers_init); + logger().info("Cluster boundary weight: %g\n", cb_index); } }; @@ -578,7 +578,7 @@ public: int clusterCount = getMinVarianceClusters(root, clusters, numClusters, variance); -// logger.info("Clusters requested: %d, returning %d\n",numClusters, clusterCount); +// logger().info("Clusters requested: %d, returning %d\n",numClusters, clusterCount); for (int i=0;ichilds[c] = pool.allocate(); node->childs[c]->radius = radiuses[c]; diff --git a/modules/flann/include/opencv2/flann/linear_index.h b/modules/flann/include/opencv2/flann/linear_index.h index b9fe4a6d65..e55ef08408 100644 --- a/modules/flann/include/opencv2/flann/linear_index.h +++ b/modules/flann/include/opencv2/flann/linear_index.h @@ -38,14 +38,14 @@ namespace cvflann { -struct LinearIndexParams : public IndexParams { +struct CV_EXPORTS LinearIndexParams : public IndexParams { LinearIndexParams() : IndexParams(LINEAR) {}; flann_algorithm_t getIndexType() const { return algorithm; } void print() const { - logger.info("Index type: %d\n",(int)algorithm); + logger().info("Index type: %d\n",(int)algorithm); } }; diff --git a/modules/flann/include/opencv2/flann/logger.h b/modules/flann/include/opencv2/flann/logger.h index 5d9a991eab..d8a9edc521 100644 --- a/modules/flann/include/opencv2/flann/logger.h +++ b/modules/flann/include/opencv2/flann/logger.h @@ -40,7 +40,7 @@ using namespace std; namespace cvflann { -class Logger +class CV_EXPORTS Logger { FILE* stream; int logLevel; @@ -84,7 +84,7 @@ public: int info(const char* fmt, ...); }; -extern Logger logger; +CV_EXPORTS Logger& logger(); } // namespace cvflann diff --git a/modules/flann/include/opencv2/flann/object_factory.h b/modules/flann/include/opencv2/flann/object_factory.h index 7318ec6446..3aa5d13309 100644 --- a/modules/flann/include/opencv2/flann/object_factory.h +++ b/modules/flann/include/opencv2/flann/object_factory.h @@ -31,6 +31,7 @@ #ifndef OBJECT_FACTORY_H_ #define OBJECT_FACTORY_H_ +#include "opencv2/core/types_c.h" #include namespace cvflann diff --git a/modules/flann/include/opencv2/flann/random.h b/modules/flann/include/opencv2/flann/random.h index b08a269353..c491ea162c 100644 --- a/modules/flann/include/opencv2/flann/random.h +++ b/modules/flann/include/opencv2/flann/random.h @@ -43,17 +43,17 @@ namespace cvflann /** * Seeds the random number generator */ -void seed_random(unsigned int seed); +CV_EXPORTS void seed_random(unsigned int seed); /* * Generates a random double value. */ -double rand_double(double high = 1.0, double low=0); +CV_EXPORTS double rand_double(double high = 1.0, double low=0); /* * Generates a random integer value. */ -int rand_int(int high = RAND_MAX, int low = 0); +CV_EXPORTS int rand_int(int high = RAND_MAX, int low = 0); /** @@ -63,7 +63,7 @@ int rand_int(int high = RAND_MAX, int low = 0); * TODO: improve on this to use a generator function instead of an * array of randomly permuted numbers */ -class UniqueRandom +class CV_EXPORTS UniqueRandom { int* vals; int size; diff --git a/modules/flann/include/opencv2/flann/result_set.h b/modules/flann/include/opencv2/flann/result_set.h index 241e7d500d..b6a084d81c 100644 --- a/modules/flann/include/opencv2/flann/result_set.h +++ b/modules/flann/include/opencv2/flann/result_set.h @@ -161,7 +161,7 @@ public: for (int i=0;i struct Datatype { static flann_datatype_t type() { return FLOA template<> struct Datatype { static flann_datatype_t type() { return FLOAT64; } }; -extern const char FLANN_SIGNATURE[]; -extern const char FLANN_VERSION[]; +CV_EXPORTS const char* FLANN_SIGNATURE(); +CV_EXPORTS const char* FLANN_VERSION(); /** * Structure representing the index header. */ -struct IndexHeader +struct CV_EXPORTS IndexHeader { char signature[16]; char version[16]; @@ -74,12 +74,12 @@ void save_header(FILE* stream, const NNIndex& index) { IndexHeader header; memset(header.signature, 0 , sizeof(header.signature)); - strcpy(header.signature, FLANN_SIGNATURE); + strcpy(header.signature, FLANN_SIGNATURE()); memset(header.version, 0 , sizeof(header.version)); - strcpy(header.version, FLANN_VERSION); + strcpy(header.version, FLANN_VERSION()); header.data_type = Datatype::type(); header.index_type = index.getType(); - header.rows = index.size(); + header.rows = (int)index.size(); header.cols = index.veclen(); std::fwrite(&header, sizeof(header),1,stream); @@ -91,7 +91,7 @@ void save_header(FILE* stream, const NNIndex& index) * @param stream - Stream to load from * @return Index header */ -IndexHeader load_header(FILE* stream); +CV_EXPORTS IndexHeader load_header(FILE* stream); template diff --git a/modules/flann/include/opencv2/flann/simplex_downhill.h b/modules/flann/include/opencv2/flann/simplex_downhill.h index 5e0f665edb..18c42ca759 100644 --- a/modules/flann/include/opencv2/flann/simplex_downhill.h +++ b/modules/flann/include/opencv2/flann/simplex_downhill.h @@ -123,7 +123,7 @@ float optimizeSimplexDownhill(T* points, int n, F func, float* vals = NULL ) if (val_r>=vals[0] && val_r -#include -#include - -#include "opencv2/flann/dist.h" -#include "opencv2/flann/index_testing.h" -#include "opencv2/flann/logger.h" -#include "opencv2/flann/logger.h" -#include "opencv2/flann/saving.h" -#include "opencv2/flann/general.h" - -// index types -#include "opencv2/flann/all_indices.h" +#include "precomp.hpp" namespace cvflann { @@ -47,17 +35,20 @@ namespace cvflann /** Global variable indicating the distance metric * to be used. */ -flann_distance_t flann_distance_type = EUCLIDEAN; +flann_distance_t flann_distance_type_ = EUCLIDEAN; +flann_distance_t flann_distance_type() { return flann_distance_type_; } /** * Zero iterator that emulates a zero feature. */ -ZeroIterator zero; +ZeroIterator zero_; +ZeroIterator& zero() { return zero_; } /** * Order of Minkowski distance to use. */ -int flann_minkowski_order; +int flann_minkowski_order_; +int flann_minkowski_order() { return flann_minkowski_order_; } double euclidean_dist(const unsigned char* first1, const unsigned char* last1, unsigned char* first2, double acc) @@ -98,9 +89,11 @@ int countCorrectMatches(int* neighbors, int* groundTruth, int n) return count; } -// ----------------------- logger.cpp --------------------------- +// ----------------------- logger().cpp --------------------------- + +Logger logger_; -Logger logger; +Logger& logger() { return logger_; } int Logger::log(int level, const char* fmt, ...) { @@ -163,20 +156,22 @@ int rand_int(int high, int low) // ----------------------- saving.cpp --------------------------- -const char FLANN_SIGNATURE[] = "FLANN_INDEX"; -const char FLANN_VERSION[] = "1.5.0"; +const char FLANN_SIGNATURE_[] = "FLANN_INDEX"; +const char FLANN_VERSION_[] = "1.5.0"; +const char* FLANN_SIGNATURE() { return FLANN_SIGNATURE_; } +const char* FLANN_VERSION() { return FLANN_VERSION_; } IndexHeader load_header(FILE* stream) { IndexHeader header; - int read_size = fread(&header,sizeof(header),1,stream); + size_t read_size = fread(&header,sizeof(header),1,stream); if (read_size!=1) { throw FLANNException("Invalid index file, cannot read"); } - if (strcmp(header.signature,FLANN_SIGNATURE)!=0) { + if (strcmp(header.signature,FLANN_SIGNATURE())!=0) { throw FLANNException("Invalid index file, wrong signature"); } @@ -190,14 +185,14 @@ IndexHeader load_header(FILE* stream) void log_verbosity(int level) { if (level>=0) { - logger.setLevel(level); + logger().setLevel(level); } } void set_distance_type(flann_distance_t distance_type, int order) { - flann_distance_type = distance_type; - flann_minkowski_order = order; + flann_distance_type_ = distance_type; + flann_minkowski_order_ = order; } class StaticInit diff --git a/modules/flann/src/precomp.cpp b/modules/flann/src/precomp.cpp new file mode 100644 index 0000000000..c149df18f9 --- /dev/null +++ b/modules/flann/src/precomp.cpp @@ -0,0 +1 @@ +#include "precomp.hpp" diff --git a/modules/flann/src/precomp.hpp b/modules/flann/src/precomp.hpp index e69de29bb2..bcf411f011 100644 --- a/modules/flann/src/precomp.hpp +++ b/modules/flann/src/precomp.hpp @@ -0,0 +1,18 @@ +#ifndef _OPENCV_FLANN_PRECOMP_HPP_ +#define _OPENCV_FLANN_PRECOMP_HPP_ + +#include +#include +#include + +#include "opencv2/flann/dist.h" +#include "opencv2/flann/index_testing.h" +#include "opencv2/flann/logger.h" +#include "opencv2/flann/saving.h" +#include "opencv2/flann/general.h" + +// index types +#include "opencv2/flann/all_indices.h" + +#endif + diff --git a/modules/objdetect/src/_lsvm_error.h b/modules/objdetect/src/_lsvm_error.h index dedd03bf39..7de5448e0b 100644 --- a/modules/objdetect/src/_lsvm_error.h +++ b/modules/objdetect/src/_lsvm_error.h @@ -1,5 +1,5 @@ -#ifndef SVM_ERROR -#define SVM_ERROR +#ifndef LSVM_ERROR +#define LSVM_ERROR #define LATENT_SVM_OK 0 #define DISTANCE_TRANSFORM_OK 1 @@ -13,4 +13,4 @@ #define FFT_OK 2 #define FFT_ERROR -8 -#endif \ No newline at end of file +#endif diff --git a/samples/c/find_obj.cpp b/samples/c/find_obj.cpp index 8faa31dd9e..134138c58a 100644 --- a/samples/c/find_obj.cpp +++ b/samples/c/find_obj.cpp @@ -171,7 +171,7 @@ locatePlanarObject( const CvSeq* objectKeypoints, const CvSeq* objectDescriptors findPairs( objectKeypoints, objectDescriptors, imageKeypoints, imageDescriptors, ptpairs ); #endif - n = ptpairs.size()/2; + n = (int)(ptpairs.size()/2); if( n < 4 ) return 0;