From: Vadim Pisarevsky Date: Fri, 8 Jul 2011 16:14:13 +0000 (+0000) Subject: re-added the opencv_flann documentation X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~6691 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f0c17b59246161089784f4ce027247a6c74eb3c;p=platform%2Fupstream%2Fopencv.git re-added the opencv_flann documentation --- diff --git a/modules/flann/doc/flann.rst b/modules/flann/doc/flann.rst new file mode 100644 index 0000000..7eee435 --- /dev/null +++ b/modules/flann/doc/flann.rst @@ -0,0 +1,9 @@ +******************************************************** +flann. Clustering and Search in Multi-Dimensional Spaces +******************************************************** + +.. toctree:: + :maxdepth: 2 + + flann_fast_approximate_nearest_neighbor_search + flann_clustering diff --git a/modules/flann/doc/flann_clustering.rst b/modules/flann/doc/flann_clustering.rst new file mode 100644 index 0000000..4ea53bd --- /dev/null +++ b/modules/flann/doc/flann_clustering.rst @@ -0,0 +1,18 @@ +Clustering +========== + +.. highlight:: cpp + +flann::hierarchicalClustering +-------------------------------------------- +Clusters features using hierarchical k-means algorithm. + +.. ocv:function:: int flann::hierarchicalClustering(const Mat& features, Mat& centers, const KMeansIndexParams& params) + + :param features: The points to be clustered. The matrix must have elements of type ET. + + :param centers: The centers of the clusters obtained. The matrix must have type DT. The number of rows in this matrix represents the number of clusters desired, however, because of the way the cut in the hierarchical tree is chosen, the number of clusters computed will be the highest number of the form ``(branching-1)*k+1`` that's lower than the number of clusters desired, where ``branching`` is the tree's branching factor (see description of the KMeansIndexParams). + + :param params: Parameters used in the construction of the hierarchical k-means tree + +The method clusters the given feature vectors by constructing a hierarchical k-means tree and choosing a cut in the tree that minimizes the cluster's variance. It returns the number of clusters found. diff --git a/modules/flann/doc/flann_fast_approximate_nearest_neighbor_search.rst b/modules/flann/doc/flann_fast_approximate_nearest_neighbor_search.rst new file mode 100644 index 0000000..5819c02 --- /dev/null +++ b/modules/flann/doc/flann_fast_approximate_nearest_neighbor_search.rst @@ -0,0 +1,193 @@ +Fast Approximate Nearest Neighbor Search +======================================== + +.. highlight:: cpp + + +This section documents OpenCV's interface to the FLANN library. FLANN (Fast Library for Approximate Nearest Neighbors) is a library that contains a collection of algorithms optimized for fast nearest neighbor search in large datasets and for high dimensional features. More information about FLANN can be found in [Muja2009]_ . + + +flann::Index\_ +----------------- + +.. ocv:class:: cv::flann::Index_ + +The FLANN nearest neighbor index class. This class is templated with the type of elements for which the index is built. + + +flann::Index_::Index\_ +-------------------------- +Constructs a nearest neighbor search index for a given dataset. + +.. ocv:function:: flann::Index_::Index_(const Mat& features, const IndexParams& params) + + :param features: Matrix of containing the features(points) to index. The size of the matrix is ``num_features x feature_dimensionality`` and the data type of the elements in the matrix must coincide with the type of the index. + + :param params: Structure containing the index parameters. The type of index that will be constructed depends on the type of this parameter. See the description. + +The method constructs a fast search structure from a set of features using the specified algorithm with specified parameters, as defined by ``params``. ``params`` is a reference to one of the following class ``IndexParams`` descendants: + + * + + **LinearIndexParams** When passing an object of this type, the index will perform a linear, brute-force search. :: + + struct LinearIndexParams : public IndexParams + { + }; + + .. + + * + + **KDTreeIndexParams** When passing an object of this type the index constructed will consist of a set of randomized kd-trees which will be searched in parallel. :: + + struct KDTreeIndexParams : public IndexParams + { + KDTreeIndexParams( int trees = 4 ); + }; + + .. + + * **trees** The number of parallel kd-trees to use. Good values are in the range [1..16] + + * + + **KMeansIndexParams** When passing an object of this type the index constructed will be a hierarchical k-means tree. :: + + struct KMeansIndexParams : public IndexParams + { + KMeansIndexParams( + int branching = 32, + int iterations = 11, + flann_centers_init_t centers_init = CENTERS_RANDOM, + float cb_index = 0.2 ); + }; + + .. + + * **branching** The branching factor to use for the hierarchical k-means tree + + * **iterations** The maximum number of iterations to use in the k-means clustering stage when building the k-means tree. A value of -1 used here means that the k-means clustering should be iterated until convergence + + * **centers_init** The algorithm to use for selecting the initial centers when performing a k-means clustering step. The possible values are ``CENTERS_RANDOM`` (picks the initial cluster centers randomly), ``CENTERS_GONZALES`` (picks the initial centers using Gonzales' algorithm) and ``CENTERS_KMEANSPP`` (picks the initial centers using the algorithm suggested in arthur_kmeanspp_2007 ) + + * **cb_index** This parameter (cluster boundary index) influences the way exploration is performed in the hierarchical kmeans tree. When ``cb_index`` is zero the next kmeans domain to be explored is choosen to be the one with the closest center. A value greater then zero also takes into account the size of the domain. + + * + **CompositeIndexParams** When using a parameters object of this type the index created combines the randomized kd-trees and the hierarchical k-means tree. :: + + 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 ); + }; + + .. + + * + **AutotunedIndexParams** When passing an object of this type the index created is automatically tuned to offer the best performance, by choosing the optimal index type (randomized kd-trees, hierarchical kmeans, linear) and parameters for the dataset provided. :: + + struct AutotunedIndexParams : public IndexParams + { + AutotunedIndexParams( + float target_precision = 0.9, + float build_weight = 0.01, + float memory_weight = 0, + float sample_fraction = 0.1 ); + }; + + .. + + * **target_precision** Is a number between 0 and 1 specifying the percentage of the approximate nearest-neighbor searches that return the exact nearest-neighbor. Using a higher value for this parameter gives more accurate results, but the search takes longer. The optimum value usually depends on the application. + + + * **build_weight** Specifies the importance of the index build time raported to the nearest-neighbor search time. In some applications it's acceptable for the index build step to take a long time if the subsequent searches in the index can be performed very fast. In other applications it's required that the index be build as fast as possible even if that leads to slightly longer search times. + + + * **memory_weight** Is used to specify the tradeoff between time (index build time and search time) and memory used by the index. A value less than 1 gives more importance to the time spent and a value greater than 1 gives more importance to the memory usage. + + + * **sample_fraction** Is a number between 0 and 1 indicating what fraction of the dataset to use in the automatic parameter configuration algorithm. Running the algorithm on the full dataset gives the most accurate results, but for very large datasets can take longer than desired. In such case using just a fraction of the data helps speeding up this algorithm while still giving good approximations of the optimum parameters. + + * + **SavedIndexParams** This object type is used for loading a previously saved index from the disk. :: + + struct SavedIndexParams : public IndexParams + { + SavedIndexParams( std::string filename ); + }; + + + .. + + * **filename** The filename in which the index was saved. + + +flann::Index_::knnSearch +---------------------------- +Performs a K-nearest neighbor search for a given query point using the index. + +.. ocv:function:: void flann::Index_::knnSearch(const vector& query, vector& indices, vector& dists, int knn, const SearchParams& params) + +.. ocv:function:: void flann::Index_::knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const SearchParams& params) + + :param query: The query point + + :param indices: Vector that will contain the indices of the K-nearest neighbors found. It must have at least knn size. + + :param dists: Vector that will contain the distances to the K-nearest neighbors found. It must have at least knn size. + + :param knn: Number of nearest neighbors to search for. + + :param params: + + Search parameters :: + + struct SearchParams { + SearchParams(int checks = 32); + }; + + .. + + * **checks** The number of times the tree(s) in the index should be recursively traversed. A higher value for this parameter would give better search precision, but also take more time. If automatic configuration was used when the index was created, the number of checks required to achieve the specified precision was also computed, in which case this parameter is ignored. + + +flann::Index_::radiusSearch +-------------------------------------- +Performs a radius nearest neighbor search for a given query point. + +.. ocv:function:: int flann::Index_::radiusSearch(const vector& query, vector& indices, vector& dists, float radius, const SearchParams& params) + +.. ocv:function:: int flann::Index_::radiusSearch(const Mat& query, Mat& indices, Mat& dists, float radius, const SearchParams& params) + + :param query: The query point + + :param indices: Vector that will contain the indices of the points found within the search radius in decreasing order of the distance to the query point. If the number of neighbors in the search radius is bigger than the size of this vector, the ones that don't fit in the vector are ignored. + + :param dists: Vector that will contain the distances to the points found within the search radius + + :param radius: The search radius + + :param params: Search parameters + + +flann::Index_::save +------------------------------ +Saves the index to a file. + +.. ocv:function:: void flann::Index_::save(std::string filename) + + :param filename: The file to save the index to + + +flann::Index_::getIndexParameters +-------------------------------------------- +Returns the index paramreters. + +.. ocv:function:: const IndexParams* flann::Index_::getIndexParameters() + +The method is useful in the case of auto-tuned indices, when the parameters are chosen during the index construction. Then, the method can be used to retrieve the actual parameter values. diff --git a/modules/refman.rst b/modules/refman.rst index 6ed01a4..5dc0c13 100644 --- a/modules/refman.rst +++ b/modules/refman.rst @@ -14,4 +14,5 @@ OpenCV API Reference features2d/doc/features2d.rst objdetect/doc/objdetect.rst ml/doc/ml.rst + flann/doc/flann.rst gpu/doc/gpu.rst