openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:0e0631af0305 1 /*M///////////////////////////////////////////////////////////////////////////////////////
RyoheiHagimoto 0:0e0631af0305 2 //
RyoheiHagimoto 0:0e0631af0305 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
RyoheiHagimoto 0:0e0631af0305 4 //
RyoheiHagimoto 0:0e0631af0305 5 // By downloading, copying, installing or using the software you agree to this license.
RyoheiHagimoto 0:0e0631af0305 6 // If you do not agree to this license, do not download, install,
RyoheiHagimoto 0:0e0631af0305 7 // copy or use the software.
RyoheiHagimoto 0:0e0631af0305 8 //
RyoheiHagimoto 0:0e0631af0305 9 //
RyoheiHagimoto 0:0e0631af0305 10 // License Agreement
RyoheiHagimoto 0:0e0631af0305 11 // For Open Source Computer Vision Library
RyoheiHagimoto 0:0e0631af0305 12 //
RyoheiHagimoto 0:0e0631af0305 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
RyoheiHagimoto 0:0e0631af0305 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
RyoheiHagimoto 0:0e0631af0305 15 // Third party copyrights are property of their respective owners.
RyoheiHagimoto 0:0e0631af0305 16 //
RyoheiHagimoto 0:0e0631af0305 17 // Redistribution and use in source and binary forms, with or without modification,
RyoheiHagimoto 0:0e0631af0305 18 // are permitted provided that the following conditions are met:
RyoheiHagimoto 0:0e0631af0305 19 //
RyoheiHagimoto 0:0e0631af0305 20 // * Redistribution's of source code must retain the above copyright notice,
RyoheiHagimoto 0:0e0631af0305 21 // this list of conditions and the following disclaimer.
RyoheiHagimoto 0:0e0631af0305 22 //
RyoheiHagimoto 0:0e0631af0305 23 // * Redistribution's in binary form must reproduce the above copyright notice,
RyoheiHagimoto 0:0e0631af0305 24 // this list of conditions and the following disclaimer in the documentation
RyoheiHagimoto 0:0e0631af0305 25 // and/or other materials provided with the distribution.
RyoheiHagimoto 0:0e0631af0305 26 //
RyoheiHagimoto 0:0e0631af0305 27 // * The name of the copyright holders may not be used to endorse or promote products
RyoheiHagimoto 0:0e0631af0305 28 // derived from this software without specific prior written permission.
RyoheiHagimoto 0:0e0631af0305 29 //
RyoheiHagimoto 0:0e0631af0305 30 // This software is provided by the copyright holders and contributors "as is" and
RyoheiHagimoto 0:0e0631af0305 31 // any express or implied warranties, including, but not limited to, the implied
RyoheiHagimoto 0:0e0631af0305 32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
RyoheiHagimoto 0:0e0631af0305 33 // In no event shall the Intel Corporation or contributors be liable for any direct,
RyoheiHagimoto 0:0e0631af0305 34 // indirect, incidental, special, exemplary, or consequential damages
RyoheiHagimoto 0:0e0631af0305 35 // (including, but not limited to, procurement of substitute goods or services;
RyoheiHagimoto 0:0e0631af0305 36 // loss of use, data, or profits; or business interruption) however caused
RyoheiHagimoto 0:0e0631af0305 37 // and on any theory of liability, whether in contract, strict liability,
RyoheiHagimoto 0:0e0631af0305 38 // or tort (including negligence or otherwise) arising in any way out of
RyoheiHagimoto 0:0e0631af0305 39 // the use of this software, even if advised of the possibility of such damage.
RyoheiHagimoto 0:0e0631af0305 40 //
RyoheiHagimoto 0:0e0631af0305 41 //M*/
RyoheiHagimoto 0:0e0631af0305 42
RyoheiHagimoto 0:0e0631af0305 43 #ifndef OPENCV_FLANN_HPP
RyoheiHagimoto 0:0e0631af0305 44 #define OPENCV_FLANN_HPP
RyoheiHagimoto 0:0e0631af0305 45
RyoheiHagimoto 0:0e0631af0305 46 #include "opencv2/core.hpp"
RyoheiHagimoto 0:0e0631af0305 47 #include "opencv2/flann/miniflann.hpp"
RyoheiHagimoto 0:0e0631af0305 48 #include "opencv2/flann/flann_base.hpp"
RyoheiHagimoto 0:0e0631af0305 49
RyoheiHagimoto 0:0e0631af0305 50 /**
RyoheiHagimoto 0:0e0631af0305 51 @defgroup flann Clustering and Search in Multi-Dimensional Spaces
RyoheiHagimoto 0:0e0631af0305 52
RyoheiHagimoto 0:0e0631af0305 53 This section documents OpenCV's interface to the FLANN library. FLANN (Fast Library for Approximate
RyoheiHagimoto 0:0e0631af0305 54 Nearest Neighbors) is a library that contains a collection of algorithms optimized for fast nearest
RyoheiHagimoto 0:0e0631af0305 55 neighbor search in large datasets and for high dimensional features. More information about FLANN
RyoheiHagimoto 0:0e0631af0305 56 can be found in @cite Muja2009 .
RyoheiHagimoto 0:0e0631af0305 57 */
RyoheiHagimoto 0:0e0631af0305 58
RyoheiHagimoto 0:0e0631af0305 59 namespace cvflann
RyoheiHagimoto 0:0e0631af0305 60 {
RyoheiHagimoto 0:0e0631af0305 61 CV_EXPORTS flann_distance_t flann_distance_type();
RyoheiHagimoto 0:0e0631af0305 62 FLANN_DEPRECATED CV_EXPORTS void set_distance_type(flann_distance_t distance_type, int order);
RyoheiHagimoto 0:0e0631af0305 63 }
RyoheiHagimoto 0:0e0631af0305 64
RyoheiHagimoto 0:0e0631af0305 65
RyoheiHagimoto 0:0e0631af0305 66 namespace cv
RyoheiHagimoto 0:0e0631af0305 67 {
RyoheiHagimoto 0:0e0631af0305 68 namespace flann
RyoheiHagimoto 0:0e0631af0305 69 {
RyoheiHagimoto 0:0e0631af0305 70
RyoheiHagimoto 0:0e0631af0305 71
RyoheiHagimoto 0:0e0631af0305 72 //! @addtogroup flann
RyoheiHagimoto 0:0e0631af0305 73 //! @{
RyoheiHagimoto 0:0e0631af0305 74
RyoheiHagimoto 0:0e0631af0305 75 template <typename T> struct CvType {};
RyoheiHagimoto 0:0e0631af0305 76 template <> struct CvType<unsigned char> { static int type() { return CV_8U; } };
RyoheiHagimoto 0:0e0631af0305 77 template <> struct CvType<char> { static int type() { return CV_8S; } };
RyoheiHagimoto 0:0e0631af0305 78 template <> struct CvType<unsigned short> { static int type() { return CV_16U; } };
RyoheiHagimoto 0:0e0631af0305 79 template <> struct CvType<short> { static int type() { return CV_16S; } };
RyoheiHagimoto 0:0e0631af0305 80 template <> struct CvType<int> { static int type() { return CV_32S; } };
RyoheiHagimoto 0:0e0631af0305 81 template <> struct CvType<float> { static int type() { return CV_32F; } };
RyoheiHagimoto 0:0e0631af0305 82 template <> struct CvType<double> { static int type() { return CV_64F; } };
RyoheiHagimoto 0:0e0631af0305 83
RyoheiHagimoto 0:0e0631af0305 84
RyoheiHagimoto 0:0e0631af0305 85 // bring the flann parameters into this namespace
RyoheiHagimoto 0:0e0631af0305 86 using ::cvflann::get_param;
RyoheiHagimoto 0:0e0631af0305 87 using ::cvflann::print_params;
RyoheiHagimoto 0:0e0631af0305 88
RyoheiHagimoto 0:0e0631af0305 89 // bring the flann distances into this namespace
RyoheiHagimoto 0:0e0631af0305 90 using ::cvflann::L2_Simple;
RyoheiHagimoto 0:0e0631af0305 91 using ::cvflann::L2;
RyoheiHagimoto 0:0e0631af0305 92 using ::cvflann::L1;
RyoheiHagimoto 0:0e0631af0305 93 using ::cvflann::MinkowskiDistance;
RyoheiHagimoto 0:0e0631af0305 94 using ::cvflann::MaxDistance;
RyoheiHagimoto 0:0e0631af0305 95 using ::cvflann::HammingLUT;
RyoheiHagimoto 0:0e0631af0305 96 using ::cvflann::Hamming;
RyoheiHagimoto 0:0e0631af0305 97 using ::cvflann::Hamming2;
RyoheiHagimoto 0:0e0631af0305 98 using ::cvflann::HistIntersectionDistance;
RyoheiHagimoto 0:0e0631af0305 99 using ::cvflann::HellingerDistance;
RyoheiHagimoto 0:0e0631af0305 100 using ::cvflann::ChiSquareDistance;
RyoheiHagimoto 0:0e0631af0305 101 using ::cvflann::KL_Divergence;
RyoheiHagimoto 0:0e0631af0305 102
RyoheiHagimoto 0:0e0631af0305 103
RyoheiHagimoto 0:0e0631af0305 104 /** @brief The FLANN nearest neighbor index class. This class is templated with the type of elements for which
RyoheiHagimoto 0:0e0631af0305 105 the index is built.
RyoheiHagimoto 0:0e0631af0305 106 */
RyoheiHagimoto 0:0e0631af0305 107 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 108 class GenericIndex
RyoheiHagimoto 0:0e0631af0305 109 {
RyoheiHagimoto 0:0e0631af0305 110 public:
RyoheiHagimoto 0:0e0631af0305 111 typedef typename Distance::ElementType ElementType;
RyoheiHagimoto 0:0e0631af0305 112 typedef typename Distance::ResultType DistanceType;
RyoheiHagimoto 0:0e0631af0305 113
RyoheiHagimoto 0:0e0631af0305 114 /** @brief Constructs a nearest neighbor search index for a given dataset.
RyoheiHagimoto 0:0e0631af0305 115
RyoheiHagimoto 0:0e0631af0305 116 @param features Matrix of containing the features(points) to index. The size of the matrix is
RyoheiHagimoto 0:0e0631af0305 117 num_features x feature_dimensionality and the data type of the elements in the matrix must
RyoheiHagimoto 0:0e0631af0305 118 coincide with the type of the index.
RyoheiHagimoto 0:0e0631af0305 119 @param params Structure containing the index parameters. The type of index that will be
RyoheiHagimoto 0:0e0631af0305 120 constructed depends on the type of this parameter. See the description.
RyoheiHagimoto 0:0e0631af0305 121 @param distance
RyoheiHagimoto 0:0e0631af0305 122
RyoheiHagimoto 0:0e0631af0305 123 The method constructs a fast search structure from a set of features using the specified algorithm
RyoheiHagimoto 0:0e0631af0305 124 with specified parameters, as defined by params. params is a reference to one of the following class
RyoheiHagimoto 0:0e0631af0305 125 IndexParams descendants:
RyoheiHagimoto 0:0e0631af0305 126
RyoheiHagimoto 0:0e0631af0305 127 - **LinearIndexParams** When passing an object of this type, the index will perform a linear,
RyoheiHagimoto 0:0e0631af0305 128 brute-force search. :
RyoheiHagimoto 0:0e0631af0305 129 @code
RyoheiHagimoto 0:0e0631af0305 130 struct LinearIndexParams : public IndexParams
RyoheiHagimoto 0:0e0631af0305 131 {
RyoheiHagimoto 0:0e0631af0305 132 };
RyoheiHagimoto 0:0e0631af0305 133 @endcode
RyoheiHagimoto 0:0e0631af0305 134 - **KDTreeIndexParams** When passing an object of this type the index constructed will consist of
RyoheiHagimoto 0:0e0631af0305 135 a set of randomized kd-trees which will be searched in parallel. :
RyoheiHagimoto 0:0e0631af0305 136 @code
RyoheiHagimoto 0:0e0631af0305 137 struct KDTreeIndexParams : public IndexParams
RyoheiHagimoto 0:0e0631af0305 138 {
RyoheiHagimoto 0:0e0631af0305 139 KDTreeIndexParams( int trees = 4 );
RyoheiHagimoto 0:0e0631af0305 140 };
RyoheiHagimoto 0:0e0631af0305 141 @endcode
RyoheiHagimoto 0:0e0631af0305 142 - **KMeansIndexParams** When passing an object of this type the index constructed will be a
RyoheiHagimoto 0:0e0631af0305 143 hierarchical k-means tree. :
RyoheiHagimoto 0:0e0631af0305 144 @code
RyoheiHagimoto 0:0e0631af0305 145 struct KMeansIndexParams : public IndexParams
RyoheiHagimoto 0:0e0631af0305 146 {
RyoheiHagimoto 0:0e0631af0305 147 KMeansIndexParams(
RyoheiHagimoto 0:0e0631af0305 148 int branching = 32,
RyoheiHagimoto 0:0e0631af0305 149 int iterations = 11,
RyoheiHagimoto 0:0e0631af0305 150 flann_centers_init_t centers_init = CENTERS_RANDOM,
RyoheiHagimoto 0:0e0631af0305 151 float cb_index = 0.2 );
RyoheiHagimoto 0:0e0631af0305 152 };
RyoheiHagimoto 0:0e0631af0305 153 @endcode
RyoheiHagimoto 0:0e0631af0305 154 - **CompositeIndexParams** When using a parameters object of this type the index created
RyoheiHagimoto 0:0e0631af0305 155 combines the randomized kd-trees and the hierarchical k-means tree. :
RyoheiHagimoto 0:0e0631af0305 156 @code
RyoheiHagimoto 0:0e0631af0305 157 struct CompositeIndexParams : public IndexParams
RyoheiHagimoto 0:0e0631af0305 158 {
RyoheiHagimoto 0:0e0631af0305 159 CompositeIndexParams(
RyoheiHagimoto 0:0e0631af0305 160 int trees = 4,
RyoheiHagimoto 0:0e0631af0305 161 int branching = 32,
RyoheiHagimoto 0:0e0631af0305 162 int iterations = 11,
RyoheiHagimoto 0:0e0631af0305 163 flann_centers_init_t centers_init = CENTERS_RANDOM,
RyoheiHagimoto 0:0e0631af0305 164 float cb_index = 0.2 );
RyoheiHagimoto 0:0e0631af0305 165 };
RyoheiHagimoto 0:0e0631af0305 166 @endcode
RyoheiHagimoto 0:0e0631af0305 167 - **LshIndexParams** When using a parameters object of this type the index created uses
RyoheiHagimoto 0:0e0631af0305 168 multi-probe LSH (by Multi-Probe LSH: Efficient Indexing for High-Dimensional Similarity Search
RyoheiHagimoto 0:0e0631af0305 169 by Qin Lv, William Josephson, Zhe Wang, Moses Charikar, Kai Li., Proceedings of the 33rd
RyoheiHagimoto 0:0e0631af0305 170 International Conference on Very Large Data Bases (VLDB). Vienna, Austria. September 2007) :
RyoheiHagimoto 0:0e0631af0305 171 @code
RyoheiHagimoto 0:0e0631af0305 172 struct LshIndexParams : public IndexParams
RyoheiHagimoto 0:0e0631af0305 173 {
RyoheiHagimoto 0:0e0631af0305 174 LshIndexParams(
RyoheiHagimoto 0:0e0631af0305 175 unsigned int table_number,
RyoheiHagimoto 0:0e0631af0305 176 unsigned int key_size,
RyoheiHagimoto 0:0e0631af0305 177 unsigned int multi_probe_level );
RyoheiHagimoto 0:0e0631af0305 178 };
RyoheiHagimoto 0:0e0631af0305 179 @endcode
RyoheiHagimoto 0:0e0631af0305 180 - **AutotunedIndexParams** When passing an object of this type the index created is
RyoheiHagimoto 0:0e0631af0305 181 automatically tuned to offer the best performance, by choosing the optimal index type
RyoheiHagimoto 0:0e0631af0305 182 (randomized kd-trees, hierarchical kmeans, linear) and parameters for the dataset provided. :
RyoheiHagimoto 0:0e0631af0305 183 @code
RyoheiHagimoto 0:0e0631af0305 184 struct AutotunedIndexParams : public IndexParams
RyoheiHagimoto 0:0e0631af0305 185 {
RyoheiHagimoto 0:0e0631af0305 186 AutotunedIndexParams(
RyoheiHagimoto 0:0e0631af0305 187 float target_precision = 0.9,
RyoheiHagimoto 0:0e0631af0305 188 float build_weight = 0.01,
RyoheiHagimoto 0:0e0631af0305 189 float memory_weight = 0,
RyoheiHagimoto 0:0e0631af0305 190 float sample_fraction = 0.1 );
RyoheiHagimoto 0:0e0631af0305 191 };
RyoheiHagimoto 0:0e0631af0305 192 @endcode
RyoheiHagimoto 0:0e0631af0305 193 - **SavedIndexParams** This object type is used for loading a previously saved index from the
RyoheiHagimoto 0:0e0631af0305 194 disk. :
RyoheiHagimoto 0:0e0631af0305 195 @code
RyoheiHagimoto 0:0e0631af0305 196 struct SavedIndexParams : public IndexParams
RyoheiHagimoto 0:0e0631af0305 197 {
RyoheiHagimoto 0:0e0631af0305 198 SavedIndexParams( String filename );
RyoheiHagimoto 0:0e0631af0305 199 };
RyoheiHagimoto 0:0e0631af0305 200 @endcode
RyoheiHagimoto 0:0e0631af0305 201 */
RyoheiHagimoto 0:0e0631af0305 202 GenericIndex(const Mat& features, const ::cvflann::IndexParams& params, Distance distance = Distance());
RyoheiHagimoto 0:0e0631af0305 203
RyoheiHagimoto 0:0e0631af0305 204 ~GenericIndex();
RyoheiHagimoto 0:0e0631af0305 205
RyoheiHagimoto 0:0e0631af0305 206 /** @brief Performs a K-nearest neighbor search for a given query point using the index.
RyoheiHagimoto 0:0e0631af0305 207
RyoheiHagimoto 0:0e0631af0305 208 @param query The query point
RyoheiHagimoto 0:0e0631af0305 209 @param indices Vector that will contain the indices of the K-nearest neighbors found. It must have
RyoheiHagimoto 0:0e0631af0305 210 at least knn size.
RyoheiHagimoto 0:0e0631af0305 211 @param dists Vector that will contain the distances to the K-nearest neighbors found. It must have
RyoheiHagimoto 0:0e0631af0305 212 at least knn size.
RyoheiHagimoto 0:0e0631af0305 213 @param knn Number of nearest neighbors to search for.
RyoheiHagimoto 0:0e0631af0305 214 @param params SearchParams
RyoheiHagimoto 0:0e0631af0305 215 */
RyoheiHagimoto 0:0e0631af0305 216 void knnSearch(const std::vector<ElementType>& query, std::vector<int>& indices,
RyoheiHagimoto 0:0e0631af0305 217 std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& params);
RyoheiHagimoto 0:0e0631af0305 218 void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& params);
RyoheiHagimoto 0:0e0631af0305 219
RyoheiHagimoto 0:0e0631af0305 220 int radiusSearch(const std::vector<ElementType>& query, std::vector<int>& indices,
RyoheiHagimoto 0:0e0631af0305 221 std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& params);
RyoheiHagimoto 0:0e0631af0305 222 int radiusSearch(const Mat& query, Mat& indices, Mat& dists,
RyoheiHagimoto 0:0e0631af0305 223 DistanceType radius, const ::cvflann::SearchParams& params);
RyoheiHagimoto 0:0e0631af0305 224
RyoheiHagimoto 0:0e0631af0305 225 void save(String filename) { nnIndex->save(filename); }
RyoheiHagimoto 0:0e0631af0305 226
RyoheiHagimoto 0:0e0631af0305 227 int veclen() const { return nnIndex->veclen(); }
RyoheiHagimoto 0:0e0631af0305 228
RyoheiHagimoto 0:0e0631af0305 229 int size() const { return nnIndex->size(); }
RyoheiHagimoto 0:0e0631af0305 230
RyoheiHagimoto 0:0e0631af0305 231 ::cvflann::IndexParams getParameters() { return nnIndex->getParameters(); }
RyoheiHagimoto 0:0e0631af0305 232
RyoheiHagimoto 0:0e0631af0305 233 FLANN_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() { return nnIndex->getIndexParameters(); }
RyoheiHagimoto 0:0e0631af0305 234
RyoheiHagimoto 0:0e0631af0305 235 private:
RyoheiHagimoto 0:0e0631af0305 236 ::cvflann::Index<Distance>* nnIndex;
RyoheiHagimoto 0:0e0631af0305 237 };
RyoheiHagimoto 0:0e0631af0305 238
RyoheiHagimoto 0:0e0631af0305 239 //! @cond IGNORED
RyoheiHagimoto 0:0e0631af0305 240
RyoheiHagimoto 0:0e0631af0305 241 #define FLANN_DISTANCE_CHECK \
RyoheiHagimoto 0:0e0631af0305 242 if ( ::cvflann::flann_distance_type() != cvflann::FLANN_DIST_L2) { \
RyoheiHagimoto 0:0e0631af0305 243 printf("[WARNING] You are using cv::flann::Index (or cv::flann::GenericIndex) and have also changed "\
RyoheiHagimoto 0:0e0631af0305 244 "the distance using cvflann::set_distance_type. This is no longer working as expected "\
RyoheiHagimoto 0:0e0631af0305 245 "(cv::flann::Index always uses L2). You should create the index templated on the distance, "\
RyoheiHagimoto 0:0e0631af0305 246 "for example for L1 distance use: GenericIndex< L1<float> > \n"); \
RyoheiHagimoto 0:0e0631af0305 247 }
RyoheiHagimoto 0:0e0631af0305 248
RyoheiHagimoto 0:0e0631af0305 249
RyoheiHagimoto 0:0e0631af0305 250 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 251 GenericIndex<Distance>::GenericIndex(const Mat& dataset, const ::cvflann::IndexParams& params, Distance distance)
RyoheiHagimoto 0:0e0631af0305 252 {
RyoheiHagimoto 0:0e0631af0305 253 CV_Assert(dataset.type() == CvType<ElementType>::type());
RyoheiHagimoto 0:0e0631af0305 254 CV_Assert(dataset.isContinuous());
RyoheiHagimoto 0:0e0631af0305 255 ::cvflann::Matrix<ElementType> m_dataset((ElementType*)dataset.ptr<ElementType>(0), dataset.rows, dataset.cols);
RyoheiHagimoto 0:0e0631af0305 256
RyoheiHagimoto 0:0e0631af0305 257 nnIndex = new ::cvflann::Index<Distance>(m_dataset, params, distance);
RyoheiHagimoto 0:0e0631af0305 258
RyoheiHagimoto 0:0e0631af0305 259 FLANN_DISTANCE_CHECK
RyoheiHagimoto 0:0e0631af0305 260
RyoheiHagimoto 0:0e0631af0305 261 nnIndex->buildIndex();
RyoheiHagimoto 0:0e0631af0305 262 }
RyoheiHagimoto 0:0e0631af0305 263
RyoheiHagimoto 0:0e0631af0305 264 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 265 GenericIndex<Distance>::~GenericIndex()
RyoheiHagimoto 0:0e0631af0305 266 {
RyoheiHagimoto 0:0e0631af0305 267 delete nnIndex;
RyoheiHagimoto 0:0e0631af0305 268 }
RyoheiHagimoto 0:0e0631af0305 269
RyoheiHagimoto 0:0e0631af0305 270 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 271 void GenericIndex<Distance>::knnSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& searchParams)
RyoheiHagimoto 0:0e0631af0305 272 {
RyoheiHagimoto 0:0e0631af0305 273 ::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
RyoheiHagimoto 0:0e0631af0305 274 ::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
RyoheiHagimoto 0:0e0631af0305 275 ::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
RyoheiHagimoto 0:0e0631af0305 276
RyoheiHagimoto 0:0e0631af0305 277 FLANN_DISTANCE_CHECK
RyoheiHagimoto 0:0e0631af0305 278
RyoheiHagimoto 0:0e0631af0305 279 nnIndex->knnSearch(m_query,m_indices,m_dists,knn,searchParams);
RyoheiHagimoto 0:0e0631af0305 280 }
RyoheiHagimoto 0:0e0631af0305 281
RyoheiHagimoto 0:0e0631af0305 282
RyoheiHagimoto 0:0e0631af0305 283 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 284 void GenericIndex<Distance>::knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams)
RyoheiHagimoto 0:0e0631af0305 285 {
RyoheiHagimoto 0:0e0631af0305 286 CV_Assert(queries.type() == CvType<ElementType>::type());
RyoheiHagimoto 0:0e0631af0305 287 CV_Assert(queries.isContinuous());
RyoheiHagimoto 0:0e0631af0305 288 ::cvflann::Matrix<ElementType> m_queries((ElementType*)queries.ptr<ElementType>(0), queries.rows, queries.cols);
RyoheiHagimoto 0:0e0631af0305 289
RyoheiHagimoto 0:0e0631af0305 290 CV_Assert(indices.type() == CV_32S);
RyoheiHagimoto 0:0e0631af0305 291 CV_Assert(indices.isContinuous());
RyoheiHagimoto 0:0e0631af0305 292 ::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
RyoheiHagimoto 0:0e0631af0305 293
RyoheiHagimoto 0:0e0631af0305 294 CV_Assert(dists.type() == CvType<DistanceType>::type());
RyoheiHagimoto 0:0e0631af0305 295 CV_Assert(dists.isContinuous());
RyoheiHagimoto 0:0e0631af0305 296 ::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
RyoheiHagimoto 0:0e0631af0305 297
RyoheiHagimoto 0:0e0631af0305 298 FLANN_DISTANCE_CHECK
RyoheiHagimoto 0:0e0631af0305 299
RyoheiHagimoto 0:0e0631af0305 300 nnIndex->knnSearch(m_queries,m_indices,m_dists,knn, searchParams);
RyoheiHagimoto 0:0e0631af0305 301 }
RyoheiHagimoto 0:0e0631af0305 302
RyoheiHagimoto 0:0e0631af0305 303 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 304 int GenericIndex<Distance>::radiusSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams)
RyoheiHagimoto 0:0e0631af0305 305 {
RyoheiHagimoto 0:0e0631af0305 306 ::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
RyoheiHagimoto 0:0e0631af0305 307 ::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
RyoheiHagimoto 0:0e0631af0305 308 ::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
RyoheiHagimoto 0:0e0631af0305 309
RyoheiHagimoto 0:0e0631af0305 310 FLANN_DISTANCE_CHECK
RyoheiHagimoto 0:0e0631af0305 311
RyoheiHagimoto 0:0e0631af0305 312 return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
RyoheiHagimoto 0:0e0631af0305 313 }
RyoheiHagimoto 0:0e0631af0305 314
RyoheiHagimoto 0:0e0631af0305 315 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 316 int GenericIndex<Distance>::radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams)
RyoheiHagimoto 0:0e0631af0305 317 {
RyoheiHagimoto 0:0e0631af0305 318 CV_Assert(query.type() == CvType<ElementType>::type());
RyoheiHagimoto 0:0e0631af0305 319 CV_Assert(query.isContinuous());
RyoheiHagimoto 0:0e0631af0305 320 ::cvflann::Matrix<ElementType> m_query((ElementType*)query.ptr<ElementType>(0), query.rows, query.cols);
RyoheiHagimoto 0:0e0631af0305 321
RyoheiHagimoto 0:0e0631af0305 322 CV_Assert(indices.type() == CV_32S);
RyoheiHagimoto 0:0e0631af0305 323 CV_Assert(indices.isContinuous());
RyoheiHagimoto 0:0e0631af0305 324 ::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
RyoheiHagimoto 0:0e0631af0305 325
RyoheiHagimoto 0:0e0631af0305 326 CV_Assert(dists.type() == CvType<DistanceType>::type());
RyoheiHagimoto 0:0e0631af0305 327 CV_Assert(dists.isContinuous());
RyoheiHagimoto 0:0e0631af0305 328 ::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
RyoheiHagimoto 0:0e0631af0305 329
RyoheiHagimoto 0:0e0631af0305 330 FLANN_DISTANCE_CHECK
RyoheiHagimoto 0:0e0631af0305 331
RyoheiHagimoto 0:0e0631af0305 332 return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
RyoheiHagimoto 0:0e0631af0305 333 }
RyoheiHagimoto 0:0e0631af0305 334
RyoheiHagimoto 0:0e0631af0305 335 //! @endcond
RyoheiHagimoto 0:0e0631af0305 336
RyoheiHagimoto 0:0e0631af0305 337 /**
RyoheiHagimoto 0:0e0631af0305 338 * @deprecated Use GenericIndex class instead
RyoheiHagimoto 0:0e0631af0305 339 */
RyoheiHagimoto 0:0e0631af0305 340 template <typename T>
RyoheiHagimoto 0:0e0631af0305 341 class Index_
RyoheiHagimoto 0:0e0631af0305 342 {
RyoheiHagimoto 0:0e0631af0305 343 public:
RyoheiHagimoto 0:0e0631af0305 344 typedef typename L2<T>::ElementType ElementType;
RyoheiHagimoto 0:0e0631af0305 345 typedef typename L2<T>::ResultType DistanceType;
RyoheiHagimoto 0:0e0631af0305 346
RyoheiHagimoto 0:0e0631af0305 347 FLANN_DEPRECATED Index_(const Mat& dataset, const ::cvflann::IndexParams& params)
RyoheiHagimoto 0:0e0631af0305 348 {
RyoheiHagimoto 0:0e0631af0305 349 printf("[WARNING] The cv::flann::Index_<T> class is deperecated, use cv::flann::GenericIndex<Distance> instead\n");
RyoheiHagimoto 0:0e0631af0305 350
RyoheiHagimoto 0:0e0631af0305 351 CV_Assert(dataset.type() == CvType<ElementType>::type());
RyoheiHagimoto 0:0e0631af0305 352 CV_Assert(dataset.isContinuous());
RyoheiHagimoto 0:0e0631af0305 353 ::cvflann::Matrix<ElementType> m_dataset((ElementType*)dataset.ptr<ElementType>(0), dataset.rows, dataset.cols);
RyoheiHagimoto 0:0e0631af0305 354
RyoheiHagimoto 0:0e0631af0305 355 if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) {
RyoheiHagimoto 0:0e0631af0305 356 nnIndex_L1 = NULL;
RyoheiHagimoto 0:0e0631af0305 357 nnIndex_L2 = new ::cvflann::Index< L2<ElementType> >(m_dataset, params);
RyoheiHagimoto 0:0e0631af0305 358 }
RyoheiHagimoto 0:0e0631af0305 359 else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) {
RyoheiHagimoto 0:0e0631af0305 360 nnIndex_L1 = new ::cvflann::Index< L1<ElementType> >(m_dataset, params);
RyoheiHagimoto 0:0e0631af0305 361 nnIndex_L2 = NULL;
RyoheiHagimoto 0:0e0631af0305 362 }
RyoheiHagimoto 0:0e0631af0305 363 else {
RyoheiHagimoto 0:0e0631af0305 364 printf("[ERROR] cv::flann::Index_<T> only provides backwards compatibility for the L1 and L2 distances. "
RyoheiHagimoto 0:0e0631af0305 365 "For other distance types you must use cv::flann::GenericIndex<Distance>\n");
RyoheiHagimoto 0:0e0631af0305 366 CV_Assert(0);
RyoheiHagimoto 0:0e0631af0305 367 }
RyoheiHagimoto 0:0e0631af0305 368 if (nnIndex_L1) nnIndex_L1->buildIndex();
RyoheiHagimoto 0:0e0631af0305 369 if (nnIndex_L2) nnIndex_L2->buildIndex();
RyoheiHagimoto 0:0e0631af0305 370 }
RyoheiHagimoto 0:0e0631af0305 371 FLANN_DEPRECATED ~Index_()
RyoheiHagimoto 0:0e0631af0305 372 {
RyoheiHagimoto 0:0e0631af0305 373 if (nnIndex_L1) delete nnIndex_L1;
RyoheiHagimoto 0:0e0631af0305 374 if (nnIndex_L2) delete nnIndex_L2;
RyoheiHagimoto 0:0e0631af0305 375 }
RyoheiHagimoto 0:0e0631af0305 376
RyoheiHagimoto 0:0e0631af0305 377 FLANN_DEPRECATED void knnSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& searchParams)
RyoheiHagimoto 0:0e0631af0305 378 {
RyoheiHagimoto 0:0e0631af0305 379 ::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
RyoheiHagimoto 0:0e0631af0305 380 ::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
RyoheiHagimoto 0:0e0631af0305 381 ::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
RyoheiHagimoto 0:0e0631af0305 382
RyoheiHagimoto 0:0e0631af0305 383 if (nnIndex_L1) nnIndex_L1->knnSearch(m_query,m_indices,m_dists,knn,searchParams);
RyoheiHagimoto 0:0e0631af0305 384 if (nnIndex_L2) nnIndex_L2->knnSearch(m_query,m_indices,m_dists,knn,searchParams);
RyoheiHagimoto 0:0e0631af0305 385 }
RyoheiHagimoto 0:0e0631af0305 386 FLANN_DEPRECATED void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams)
RyoheiHagimoto 0:0e0631af0305 387 {
RyoheiHagimoto 0:0e0631af0305 388 CV_Assert(queries.type() == CvType<ElementType>::type());
RyoheiHagimoto 0:0e0631af0305 389 CV_Assert(queries.isContinuous());
RyoheiHagimoto 0:0e0631af0305 390 ::cvflann::Matrix<ElementType> m_queries((ElementType*)queries.ptr<ElementType>(0), queries.rows, queries.cols);
RyoheiHagimoto 0:0e0631af0305 391
RyoheiHagimoto 0:0e0631af0305 392 CV_Assert(indices.type() == CV_32S);
RyoheiHagimoto 0:0e0631af0305 393 CV_Assert(indices.isContinuous());
RyoheiHagimoto 0:0e0631af0305 394 ::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
RyoheiHagimoto 0:0e0631af0305 395
RyoheiHagimoto 0:0e0631af0305 396 CV_Assert(dists.type() == CvType<DistanceType>::type());
RyoheiHagimoto 0:0e0631af0305 397 CV_Assert(dists.isContinuous());
RyoheiHagimoto 0:0e0631af0305 398 ::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
RyoheiHagimoto 0:0e0631af0305 399
RyoheiHagimoto 0:0e0631af0305 400 if (nnIndex_L1) nnIndex_L1->knnSearch(m_queries,m_indices,m_dists,knn, searchParams);
RyoheiHagimoto 0:0e0631af0305 401 if (nnIndex_L2) nnIndex_L2->knnSearch(m_queries,m_indices,m_dists,knn, searchParams);
RyoheiHagimoto 0:0e0631af0305 402 }
RyoheiHagimoto 0:0e0631af0305 403
RyoheiHagimoto 0:0e0631af0305 404 FLANN_DEPRECATED int radiusSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams)
RyoheiHagimoto 0:0e0631af0305 405 {
RyoheiHagimoto 0:0e0631af0305 406 ::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
RyoheiHagimoto 0:0e0631af0305 407 ::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
RyoheiHagimoto 0:0e0631af0305 408 ::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
RyoheiHagimoto 0:0e0631af0305 409
RyoheiHagimoto 0:0e0631af0305 410 if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
RyoheiHagimoto 0:0e0631af0305 411 if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
RyoheiHagimoto 0:0e0631af0305 412 }
RyoheiHagimoto 0:0e0631af0305 413
RyoheiHagimoto 0:0e0631af0305 414 FLANN_DEPRECATED int radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams)
RyoheiHagimoto 0:0e0631af0305 415 {
RyoheiHagimoto 0:0e0631af0305 416 CV_Assert(query.type() == CvType<ElementType>::type());
RyoheiHagimoto 0:0e0631af0305 417 CV_Assert(query.isContinuous());
RyoheiHagimoto 0:0e0631af0305 418 ::cvflann::Matrix<ElementType> m_query((ElementType*)query.ptr<ElementType>(0), query.rows, query.cols);
RyoheiHagimoto 0:0e0631af0305 419
RyoheiHagimoto 0:0e0631af0305 420 CV_Assert(indices.type() == CV_32S);
RyoheiHagimoto 0:0e0631af0305 421 CV_Assert(indices.isContinuous());
RyoheiHagimoto 0:0e0631af0305 422 ::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
RyoheiHagimoto 0:0e0631af0305 423
RyoheiHagimoto 0:0e0631af0305 424 CV_Assert(dists.type() == CvType<DistanceType>::type());
RyoheiHagimoto 0:0e0631af0305 425 CV_Assert(dists.isContinuous());
RyoheiHagimoto 0:0e0631af0305 426 ::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
RyoheiHagimoto 0:0e0631af0305 427
RyoheiHagimoto 0:0e0631af0305 428 if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
RyoheiHagimoto 0:0e0631af0305 429 if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
RyoheiHagimoto 0:0e0631af0305 430 }
RyoheiHagimoto 0:0e0631af0305 431
RyoheiHagimoto 0:0e0631af0305 432 FLANN_DEPRECATED void save(String filename)
RyoheiHagimoto 0:0e0631af0305 433 {
RyoheiHagimoto 0:0e0631af0305 434 if (nnIndex_L1) nnIndex_L1->save(filename);
RyoheiHagimoto 0:0e0631af0305 435 if (nnIndex_L2) nnIndex_L2->save(filename);
RyoheiHagimoto 0:0e0631af0305 436 }
RyoheiHagimoto 0:0e0631af0305 437
RyoheiHagimoto 0:0e0631af0305 438 FLANN_DEPRECATED int veclen() const
RyoheiHagimoto 0:0e0631af0305 439 {
RyoheiHagimoto 0:0e0631af0305 440 if (nnIndex_L1) return nnIndex_L1->veclen();
RyoheiHagimoto 0:0e0631af0305 441 if (nnIndex_L2) return nnIndex_L2->veclen();
RyoheiHagimoto 0:0e0631af0305 442 }
RyoheiHagimoto 0:0e0631af0305 443
RyoheiHagimoto 0:0e0631af0305 444 FLANN_DEPRECATED int size() const
RyoheiHagimoto 0:0e0631af0305 445 {
RyoheiHagimoto 0:0e0631af0305 446 if (nnIndex_L1) return nnIndex_L1->size();
RyoheiHagimoto 0:0e0631af0305 447 if (nnIndex_L2) return nnIndex_L2->size();
RyoheiHagimoto 0:0e0631af0305 448 }
RyoheiHagimoto 0:0e0631af0305 449
RyoheiHagimoto 0:0e0631af0305 450 FLANN_DEPRECATED ::cvflann::IndexParams getParameters()
RyoheiHagimoto 0:0e0631af0305 451 {
RyoheiHagimoto 0:0e0631af0305 452 if (nnIndex_L1) return nnIndex_L1->getParameters();
RyoheiHagimoto 0:0e0631af0305 453 if (nnIndex_L2) return nnIndex_L2->getParameters();
RyoheiHagimoto 0:0e0631af0305 454
RyoheiHagimoto 0:0e0631af0305 455 }
RyoheiHagimoto 0:0e0631af0305 456
RyoheiHagimoto 0:0e0631af0305 457 FLANN_DEPRECATED const ::cvflann::IndexParams* getIndexParameters()
RyoheiHagimoto 0:0e0631af0305 458 {
RyoheiHagimoto 0:0e0631af0305 459 if (nnIndex_L1) return nnIndex_L1->getIndexParameters();
RyoheiHagimoto 0:0e0631af0305 460 if (nnIndex_L2) return nnIndex_L2->getIndexParameters();
RyoheiHagimoto 0:0e0631af0305 461 }
RyoheiHagimoto 0:0e0631af0305 462
RyoheiHagimoto 0:0e0631af0305 463 private:
RyoheiHagimoto 0:0e0631af0305 464 // providing backwards compatibility for L2 and L1 distances (most common)
RyoheiHagimoto 0:0e0631af0305 465 ::cvflann::Index< L2<ElementType> >* nnIndex_L2;
RyoheiHagimoto 0:0e0631af0305 466 ::cvflann::Index< L1<ElementType> >* nnIndex_L1;
RyoheiHagimoto 0:0e0631af0305 467 };
RyoheiHagimoto 0:0e0631af0305 468
RyoheiHagimoto 0:0e0631af0305 469
RyoheiHagimoto 0:0e0631af0305 470 /** @brief Clusters features using hierarchical k-means algorithm.
RyoheiHagimoto 0:0e0631af0305 471
RyoheiHagimoto 0:0e0631af0305 472 @param features The points to be clustered. The matrix must have elements of type
RyoheiHagimoto 0:0e0631af0305 473 Distance::ElementType.
RyoheiHagimoto 0:0e0631af0305 474 @param centers The centers of the clusters obtained. The matrix must have type
RyoheiHagimoto 0:0e0631af0305 475 Distance::ResultType. The number of rows in this matrix represents the number of clusters desired,
RyoheiHagimoto 0:0e0631af0305 476 however, because of the way the cut in the hierarchical tree is chosen, the number of clusters
RyoheiHagimoto 0:0e0631af0305 477 computed will be the highest number of the form (branching-1)\*k+1 that's lower than the number of
RyoheiHagimoto 0:0e0631af0305 478 clusters desired, where branching is the tree's branching factor (see description of the
RyoheiHagimoto 0:0e0631af0305 479 KMeansIndexParams).
RyoheiHagimoto 0:0e0631af0305 480 @param params Parameters used in the construction of the hierarchical k-means tree.
RyoheiHagimoto 0:0e0631af0305 481 @param d Distance to be used for clustering.
RyoheiHagimoto 0:0e0631af0305 482
RyoheiHagimoto 0:0e0631af0305 483 The method clusters the given feature vectors by constructing a hierarchical k-means tree and
RyoheiHagimoto 0:0e0631af0305 484 choosing a cut in the tree that minimizes the cluster's variance. It returns the number of clusters
RyoheiHagimoto 0:0e0631af0305 485 found.
RyoheiHagimoto 0:0e0631af0305 486 */
RyoheiHagimoto 0:0e0631af0305 487 template <typename Distance>
RyoheiHagimoto 0:0e0631af0305 488 int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params,
RyoheiHagimoto 0:0e0631af0305 489 Distance d = Distance())
RyoheiHagimoto 0:0e0631af0305 490 {
RyoheiHagimoto 0:0e0631af0305 491 typedef typename Distance::ElementType ElementType;
RyoheiHagimoto 0:0e0631af0305 492 typedef typename Distance::ResultType DistanceType;
RyoheiHagimoto 0:0e0631af0305 493
RyoheiHagimoto 0:0e0631af0305 494 CV_Assert(features.type() == CvType<ElementType>::type());
RyoheiHagimoto 0:0e0631af0305 495 CV_Assert(features.isContinuous());
RyoheiHagimoto 0:0e0631af0305 496 ::cvflann::Matrix<ElementType> m_features((ElementType*)features.ptr<ElementType>(0), features.rows, features.cols);
RyoheiHagimoto 0:0e0631af0305 497
RyoheiHagimoto 0:0e0631af0305 498 CV_Assert(centers.type() == CvType<DistanceType>::type());
RyoheiHagimoto 0:0e0631af0305 499 CV_Assert(centers.isContinuous());
RyoheiHagimoto 0:0e0631af0305 500 ::cvflann::Matrix<DistanceType> m_centers((DistanceType*)centers.ptr<DistanceType>(0), centers.rows, centers.cols);
RyoheiHagimoto 0:0e0631af0305 501
RyoheiHagimoto 0:0e0631af0305 502 return ::cvflann::hierarchicalClustering<Distance>(m_features, m_centers, params, d);
RyoheiHagimoto 0:0e0631af0305 503 }
RyoheiHagimoto 0:0e0631af0305 504
RyoheiHagimoto 0:0e0631af0305 505 /** @deprecated
RyoheiHagimoto 0:0e0631af0305 506 */
RyoheiHagimoto 0:0e0631af0305 507 template <typename ELEM_TYPE, typename DIST_TYPE>
RyoheiHagimoto 0:0e0631af0305 508 FLANN_DEPRECATED int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params)
RyoheiHagimoto 0:0e0631af0305 509 {
RyoheiHagimoto 0:0e0631af0305 510 printf("[WARNING] cv::flann::hierarchicalClustering<ELEM_TYPE,DIST_TYPE> is deprecated, use "
RyoheiHagimoto 0:0e0631af0305 511 "cv::flann::hierarchicalClustering<Distance> instead\n");
RyoheiHagimoto 0:0e0631af0305 512
RyoheiHagimoto 0:0e0631af0305 513 if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) {
RyoheiHagimoto 0:0e0631af0305 514 return hierarchicalClustering< L2<ELEM_TYPE> >(features, centers, params);
RyoheiHagimoto 0:0e0631af0305 515 }
RyoheiHagimoto 0:0e0631af0305 516 else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) {
RyoheiHagimoto 0:0e0631af0305 517 return hierarchicalClustering< L1<ELEM_TYPE> >(features, centers, params);
RyoheiHagimoto 0:0e0631af0305 518 }
RyoheiHagimoto 0:0e0631af0305 519 else {
RyoheiHagimoto 0:0e0631af0305 520 printf("[ERROR] cv::flann::hierarchicalClustering<ELEM_TYPE,DIST_TYPE> only provides backwards "
RyoheiHagimoto 0:0e0631af0305 521 "compatibility for the L1 and L2 distances. "
RyoheiHagimoto 0:0e0631af0305 522 "For other distance types you must use cv::flann::hierarchicalClustering<Distance>\n");
RyoheiHagimoto 0:0e0631af0305 523 CV_Assert(0);
RyoheiHagimoto 0:0e0631af0305 524 }
RyoheiHagimoto 0:0e0631af0305 525 }
RyoheiHagimoto 0:0e0631af0305 526
RyoheiHagimoto 0:0e0631af0305 527 //! @} flann
RyoheiHagimoto 0:0e0631af0305 528
RyoheiHagimoto 0:0e0631af0305 529 } } // namespace cv::flann
RyoheiHagimoto 0:0e0631af0305 530
RyoheiHagimoto 0:0e0631af0305 531 #endif