miniflann.hpp
Go to the documentation of this file.
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 
46 #ifdef __cplusplus
47 
48 #include "opencv2/core/core.hpp"
49 #include "opencv2/flann/defines.h"
50 
51 namespace cv
52 {
53 
54 namespace flann
55 {
56 
57 struct CV_EXPORTS IndexParams
58 {
59  IndexParams();
60  ~IndexParams();
61 
62  std::string getString(const std::string& key, const std::string& defaultVal=std::string()) const;
63  int getInt(const std::string& key, int defaultVal=-1) const;
64  double getDouble(const std::string& key, double defaultVal=-1) const;
65 
66  void setString(const std::string& key, const std::string& value);
67  void setInt(const std::string& key, int value);
68  void setDouble(const std::string& key, double value);
69  void setFloat(const std::string& key, float value);
70  void setBool(const std::string& key, bool value);
71  void setAlgorithm(int value);
72 
73  void getAll(std::vector<std::string>& names,
74  std::vector<int>& types,
75  std::vector<std::string>& strValues,
76  std::vector<double>& numValues) const;
77 
78  void* params;
79 };
80 
81 struct CV_EXPORTS KDTreeIndexParams : public IndexParams
82 {
83  KDTreeIndexParams(int trees=4);
84 };
85 
86 struct CV_EXPORTS LinearIndexParams : public IndexParams
87 {
89 };
90 
91 struct CV_EXPORTS CompositeIndexParams : public IndexParams
92 {
93  CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11,
94  cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2 );
95 };
96 
97 struct CV_EXPORTS AutotunedIndexParams : public IndexParams
98 {
99  AutotunedIndexParams(float target_precision = 0.8, float build_weight = 0.01,
100  float memory_weight = 0, float sample_fraction = 0.1);
101 };
102 
104 {
105  HierarchicalClusteringIndexParams(int branching = 32,
106  cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, int trees = 4, int leaf_size = 100 );
107 };
108 
109 struct CV_EXPORTS KMeansIndexParams : public IndexParams
110 {
111  KMeansIndexParams(int branching = 32, int iterations = 11,
112  cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2 );
113 };
114 
115 struct CV_EXPORTS LshIndexParams : public IndexParams
116 {
117  LshIndexParams(int table_number, int key_size, int multi_probe_level);
118 };
119 
120 struct CV_EXPORTS SavedIndexParams : public IndexParams
121 {
122  SavedIndexParams(const std::string& filename);
123 };
124 
125 struct CV_EXPORTS SearchParams : public IndexParams
126 {
127  SearchParams( int checks = 32, float eps = 0, bool sorted = true );
128 };
129 
130 class CV_EXPORTS_W Index
131 {
132 public:
133  CV_WRAP Index();
134  CV_WRAP Index(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2);
135  virtual ~Index();
136 
137  CV_WRAP virtual void build(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2);
138  CV_WRAP virtual void knnSearch(InputArray query, OutputArray indices,
139  OutputArray dists, int knn, const SearchParams& params=SearchParams());
140 
141  CV_WRAP virtual int radiusSearch(InputArray query, OutputArray indices,
142  OutputArray dists, double radius, int maxResults,
143  const SearchParams& params=SearchParams());
144 
145  CV_WRAP virtual void save(const std::string& filename) const;
146  CV_WRAP virtual bool load(InputArray features, const std::string& filename);
147  CV_WRAP virtual void release();
148  CV_WRAP cvflann::flann_distance_t getDistance() const;
149  CV_WRAP cvflann::flann_algorithm_t getAlgorithm() const;
150 
151 protected:
155  void* index;
156 };
157 
158 } } // namespace cv::flann
159 
160 #endif // __cplusplus
161 
162 #endif
Definition: miniflann.hpp:109
flann_algorithm_t
Definition: defines.h:81
const char const char ** filename
Definition: core_c.h:1750
void * params
Definition: miniflann.hpp:78
CvFileNode const CvStringHashNode * key
Definition: core_c.h:1584
Definition: defines.h:129
cvflann::flann_algorithm_t algo
Definition: miniflann.hpp:153
Definition: miniflann.hpp:130
cvflann::flann_distance_t distType
Definition: miniflann.hpp:152
int CvMemStorage int double eps
Definition: imgproc_c.h:353
Proxy datatype for passing Mat's and vector<>'s as input parameters.
Definition: core.hpp:1312
void * index
Definition: miniflann.hpp:155
SourceFileRef load(const DataSourceRef &dataSource, size_t sampleRate=0)
GLuint GLuint GLsizei GLenum const GLvoid * indices
Definition: legacy.hpp:3084
Definition: miniflann.hpp:57
const CvArr CvArr double int int int iterations
Definition: tracking.hpp:102
flann_centers_init_t
Definition: defines.h:105
The Core Functionality.
Definition: miniflann.hpp:81
GLsizei const GLfloat * value
Definition: core_c.h:341
CV_EXPORTS std::vector< MatType > types(int depth_start, int depth_end, int cn_start, int cn_end)
return vector with types from specified range.
std::map< std::string, any > IndexParams
Definition: params.h:42
GLenum const GLfloat * params
Definition: compat.hpp:688
Definition: miniflann.hpp:125
Definition: miniflann.hpp:120
Definition: miniflann.hpp:115
Definition: miniflann.hpp:97
Definition: miniflann.hpp:91
int featureType
Definition: miniflann.hpp:154
Definition: defines.h:107
Definition: miniflann.hpp:86
CvPoint int radius
Definition: core_c.h:1290
Proxy datatype for passing Mat's and vector<>'s as input parameters.
Definition: core.hpp:1400
flann_distance_t
Definition: defines.h:126