31 #ifndef OPENCV_FLANN_COMPOSITE_INDEX_H_
32 #define OPENCV_FLANN_COMPOSITE_INDEX_H_
37 #include "kdtree_index.h"
38 #include "kmeans_index.h"
46 struct CompositeIndexParams :
public IndexParams
48 CompositeIndexParams(
int trees = 4,
int branching = 32,
int iterations = 11,
49 flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM,
float cb_index = 0.2 )
51 (*this)[
"algorithm"] = FLANN_INDEX_KMEANS;
53 (*this)[
"trees"] = trees;
55 (*this)[
"branching"] = branching;
57 (*this)[
"iterations"] = iterations;
59 (*this)[
"centers_init"] = centers_init;
61 (*this)[
"cb_index"] = cb_index;
71 template <
typename Distance>
72 class CompositeIndex :
public NNIndex<Distance>
75 typedef typename Distance::ElementType ElementType;
76 typedef typename Distance::ResultType DistanceType;
84 CompositeIndex(
const Matrix<ElementType>& inputData,
const IndexParams& params = CompositeIndexParams(),
85 Distance d = Distance()) : index_params_(params)
87 kdtree_index_ =
new KDTreeIndex<Distance>(inputData, params, d);
88 kmeans_index_ =
new KMeansIndex<Distance>(inputData, params, d);
92 CompositeIndex(
const CompositeIndex&);
93 CompositeIndex& operator=(
const CompositeIndex&);
95 virtual ~CompositeIndex()
106 return FLANN_INDEX_COMPOSITE;
114 return kdtree_index_->size();
122 return kdtree_index_->veclen();
130 return kmeans_index_->usedMemory() + kdtree_index_->usedMemory();
138 Logger::info(
"Building kmeans tree...\n");
139 kmeans_index_->buildIndex();
140 Logger::info(
"Building kdtree tree...\n");
141 kdtree_index_->buildIndex();
150 kmeans_index_->saveIndex(stream);
151 kdtree_index_->saveIndex(stream);
160 kmeans_index_->loadIndex(stream);
161 kdtree_index_->loadIndex(stream);
169 return index_params_;
175 void findNeighbors(ResultSet<DistanceType>&
result,
const ElementType* vec,
const SearchParams& searchParams)
CV_OVERRIDE
177 kmeans_index_->findNeighbors(
result, vec, searchParams);
178 kdtree_index_->findNeighbors(
result, vec, searchParams);
183 KMeansIndex<Distance>* kmeans_index_;
186 KDTreeIndex<Distance>* kdtree_index_;
189 const IndexParams index_params_;
CvSize size
Definition: core_c.h:112
const CvArr const CvArr CvArr * result
Definition: core_c.h:1423
#define CV_OVERRIDE
Definition: cvdef.h:792