EstervQrCode 1.1.1
Library for qr code manipulation
miniflann.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
26 //
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #ifndef OPENCV_MINIFLANN_HPP
44 #define OPENCV_MINIFLANN_HPP
45 
47 
48 #include "opencv2/core.hpp"
49 #include "opencv2/flann/defines.h"
50 
51 namespace cv
52 {
53 
54 namespace flann
55 {
56 
57 enum FlannIndexType {
58  FLANN_INDEX_TYPE_8U = CV_8U,
59  FLANN_INDEX_TYPE_8S = CV_8S,
60  FLANN_INDEX_TYPE_16U = CV_16U,
61  FLANN_INDEX_TYPE_16S = CV_16S,
62  FLANN_INDEX_TYPE_32S = CV_32S,
63  FLANN_INDEX_TYPE_32F = CV_32F,
64  FLANN_INDEX_TYPE_64F = CV_64F,
65  FLANN_INDEX_TYPE_STRING,
66  FLANN_INDEX_TYPE_BOOL,
67  FLANN_INDEX_TYPE_ALGORITHM,
68  LAST_VALUE_FLANN_INDEX_TYPE = FLANN_INDEX_TYPE_ALGORITHM
69 };
70 
71 struct CV_EXPORTS IndexParams
72 {
73  IndexParams();
74  ~IndexParams();
75 
76  String getString(const String& key, const String& defaultVal=String()) const;
77  int getInt(const String& key, int defaultVal=-1) const;
78  double getDouble(const String& key, double defaultVal=-1) const;
79 
80  void setString(const String& key, const String& value);
81  void setInt(const String& key, int value);
82  void setDouble(const String& key, double value);
83  void setFloat(const String& key, float value);
84  void setBool(const String& key, bool value);
85  void setAlgorithm(int value);
86 
87  // FIXIT: replace by void write(FileStorage& fs) const + read()
88  void getAll(std::vector<String>& names,
90  std::vector<String>& strValues,
91  std::vector<double>& numValues) const;
92 
93  void* params;
94 
95 private:
96  IndexParams(const IndexParams &); // copy disabled
97  IndexParams& operator=(const IndexParams &); // assign disabled
98 };
99 
100 struct CV_EXPORTS KDTreeIndexParams : public IndexParams
101 {
102  KDTreeIndexParams(int trees=4);
103 };
104 
105 struct CV_EXPORTS LinearIndexParams : public IndexParams
106 {
107  LinearIndexParams();
108 };
109 
110 struct CV_EXPORTS CompositeIndexParams : public IndexParams
111 {
112  CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11,
113  cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2f );
114 };
115 
116 struct CV_EXPORTS AutotunedIndexParams : public IndexParams
117 {
118  AutotunedIndexParams(float target_precision = 0.8f, float build_weight = 0.01f,
119  float memory_weight = 0, float sample_fraction = 0.1f);
120 };
121 
122 struct CV_EXPORTS HierarchicalClusteringIndexParams : public IndexParams
123 {
124  HierarchicalClusteringIndexParams(int branching = 32,
125  cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, int trees = 4, int leaf_size = 100 );
126 };
127 
128 struct CV_EXPORTS KMeansIndexParams : public IndexParams
129 {
130  KMeansIndexParams(int branching = 32, int iterations = 11,
131  cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2f );
132 };
133 
134 struct CV_EXPORTS LshIndexParams : public IndexParams
135 {
136  LshIndexParams(int table_number, int key_size, int multi_probe_level);
137 };
138 
139 struct CV_EXPORTS SavedIndexParams : public IndexParams
140 {
141  SavedIndexParams(const String& filename);
142 };
143 
144 struct CV_EXPORTS SearchParams : public IndexParams
145 {
146  SearchParams( int checks, float eps, bool sorted, bool explore_all_trees );
147  SearchParams( int checks = 32, float eps = 0, bool sorted = true );
148 };
149 
150 class CV_EXPORTS_W Index
151 {
152 public:
153  CV_WRAP Index();
154  CV_WRAP Index(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2);
155  virtual ~Index();
156 
157  CV_WRAP virtual void build(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2);
158  CV_WRAP virtual void knnSearch(InputArray query, OutputArray indices,
159  OutputArray dists, int knn, const SearchParams& params=SearchParams());
160 
161  CV_WRAP virtual int radiusSearch(InputArray query, OutputArray indices,
162  OutputArray dists, double radius, int maxResults,
163  const SearchParams& params=SearchParams());
164 
165  CV_WRAP virtual void save(const String& filename) const;
166  CV_WRAP virtual bool load(InputArray features, const String& filename);
167  CV_WRAP virtual void release();
168  CV_WRAP cvflann::flann_distance_t getDistance() const;
169  CV_WRAP cvflann::flann_algorithm_t getAlgorithm() const;
170 
171 protected:
172  bool load_(const String& filename);
173 
174  cvflann::flann_distance_t distType;
175  cvflann::flann_algorithm_t algo;
176  int featureType;
177  void* index;
178  Mat features_clone; // index may store features pointer internally for searching, so avoid dangling pointers: https://github.com/opencv/opencv/issues/17553
179 };
180 
181 } } // namespace cv::flann
182 
184 
185 #endif
std::string String
Definition: cvstd.hpp:151
const _OutputArray & OutputArray
Definition: mat.hpp:444
CV__DEBUG_NS_END typedef const _InputArray & InputArray
Definition: mat.hpp:442
int CvScalar value
Definition: core_c.h:720
int index
Definition: core_c.h:634
const char const char ** filename
Definition: core_c.h:2630
#define CV_8S
Definition: interface.h:74
#define CV_64F
Definition: interface.h:79
#define CV_8U
Definition: interface.h:73
#define CV_32S
Definition: interface.h:77
#define CV_32F
Definition: interface.h:78
#define CV_16S
Definition: interface.h:76
#define CV_16U
Definition: interface.h:75
#define CV_EXPORTS
Definition: cvdef.h:435
#define CV_EXPORTS_W
Definition: cvdef.h:472
#define CV_WRAP
Definition: cvdef.h:481
CvPoint2D32f float * radius
Definition: imgproc_c.h:534
int CvMemStorage int double eps
Definition: imgproc_c.h:493
InputArray int distType
Definition: imgproc.hpp:3387
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441