include/opencv2/flann/miniflann.hpp
Go to the documentation of this file.
00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                           License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Third party copyrights are property of their respective owners.
00016 //
00017 // Redistribution and use in source and binary forms, with or without modification,
00018 // are permitted provided that the following conditions are met:
00019 //
00020 //   * Redistribution's of source code must retain the above copyright notice,
00021 //     this list of conditions and the following disclaimer.
00022 //
00023 //   * Redistribution's in binary form must reproduce the above copyright notice,
00024 //     this list of conditions and the following disclaimer in the documentation
00025 //     and/or other materials provided with the distribution.
00026 //
00027 //   * The name of the copyright holders may not be used to endorse or promote products
00028 //     derived from this software without specific prior written permission.
00029 //
00030 // This software is provided by the copyright holders and contributors "as is" and
00031 // any express or implied warranties, including, but not limited to, the implied
00032 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00033 // In no event shall the Intel Corporation or contributors be liable for any direct,
00034 // indirect, incidental, special, exemplary, or consequential damages
00035 // (including, but not limited to, procurement of substitute goods or services;
00036 // loss of use, data, or profits; or business interruption) however caused
00037 // and on any theory of liability, whether in contract, strict liability,
00038 // or tort (including negligence or otherwise) arising in any way out of
00039 // the use of this software, even if advised of the possibility of such damage.
00040 //
00041 //M*/
00042 
00043 #ifndef _OPENCV_MINIFLANN_HPP_
00044 #define _OPENCV_MINIFLANN_HPP_
00045 
00046 #ifdef __cplusplus
00047 
00048 #include "opencv2/core/core.hpp"
00049 #include "opencv2/flann/defines.h"
00050 
00051 namespace cv
00052 {
00053 
00054 namespace flann
00055 {
00056 
00057 struct CV_EXPORTS IndexParams
00058 {
00059     IndexParams();
00060     ~IndexParams();
00061 
00062     std::string getString(const std::string& key, const std::string& defaultVal=std::string()) const;
00063     int getInt(const std::string& key, int defaultVal=-1) const;
00064     double getDouble(const std::string& key, double defaultVal=-1) const;
00065 
00066     void setString(const std::string& key, const std::string& value);
00067     void setInt(const std::string& key, int value);
00068     void setDouble(const std::string& key, double value);
00069     void setFloat(const std::string& key, float value);
00070     void setBool(const std::string& key, bool value);
00071     void setAlgorithm(int value);
00072 
00073     void getAll(std::vector<std::string>& names,
00074                 std::vector<int>& types,
00075                 std::vector<std::string>& strValues,
00076                 std::vector<double>& numValues) const;
00077 
00078     void* params;
00079 };
00080 
00081 struct CV_EXPORTS KDTreeIndexParams : public IndexParams
00082 {
00083     KDTreeIndexParams(int trees=4);
00084 };
00085 
00086 struct CV_EXPORTS LinearIndexParams : public IndexParams
00087 {
00088     LinearIndexParams();
00089 };
00090 
00091 struct CV_EXPORTS CompositeIndexParams : public IndexParams
00092 {
00093     CompositeIndexParams(int trees = 4, int branching = 32, int iterations = 11,
00094                          cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2 );
00095 };
00096 
00097 struct CV_EXPORTS AutotunedIndexParams : public IndexParams
00098 {
00099     AutotunedIndexParams(float target_precision = 0.8, float build_weight = 0.01,
00100                          float memory_weight = 0, float sample_fraction = 0.1);
00101 };
00102 
00103 struct CV_EXPORTS HierarchicalClusteringIndexParams : public IndexParams
00104 {
00105     HierarchicalClusteringIndexParams(int branching = 32,
00106                       cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, int trees = 4, int leaf_size = 100 );
00107 };
00108 
00109 struct CV_EXPORTS KMeansIndexParams : public IndexParams
00110 {
00111     KMeansIndexParams(int branching = 32, int iterations = 11,
00112                       cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, float cb_index = 0.2 );
00113 };
00114 
00115 struct CV_EXPORTS LshIndexParams : public IndexParams
00116 {
00117     LshIndexParams(int table_number, int key_size, int multi_probe_level);
00118 };
00119 
00120 struct CV_EXPORTS SavedIndexParams : public IndexParams
00121 {
00122     SavedIndexParams(const std::string& filename);
00123 };
00124 
00125 struct CV_EXPORTS SearchParams : public IndexParams
00126 {
00127     SearchParams( int checks = 32, float eps = 0, bool sorted = true );
00128 };
00129 
00130 class CV_EXPORTS_W Index
00131 {
00132 public:
00133     CV_WRAP Index();
00134     CV_WRAP Index(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2);
00135     virtual ~Index();
00136 
00137     CV_WRAP virtual void build(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2);
00138     CV_WRAP virtual void knnSearch(InputArray query, OutputArray indices,
00139                    OutputArray dists, int knn, const SearchParams& params=SearchParams());
00140 
00141     CV_WRAP virtual int radiusSearch(InputArray query, OutputArray indices,
00142                              OutputArray dists, double radius, int maxResults,
00143                              const SearchParams& params=SearchParams());
00144 
00145     CV_WRAP virtual void save(const std::string& filename) const;
00146     CV_WRAP virtual bool load(InputArray features, const std::string& filename);
00147     CV_WRAP virtual void release();
00148     CV_WRAP cvflann::flann_distance_t getDistance() const;
00149     CV_WRAP cvflann::flann_algorithm_t getAlgorithm() const;
00150 
00151 protected:
00152     cvflann::flann_distance_t distType;
00153     cvflann::flann_algorithm_t algo;
00154     int featureType;
00155     void* index;
00156 };
00157 
00158 } } // namespace cv::flann
00159 
00160 #endif // __cplusplus
00161 
00162 #endif