31 #ifndef OPENCV_FLANN_NNINDEX_H
32 #define OPENCV_FLANN_NNINDEX_H
35 #include "result_set.h"
46 template <
typename Distance>
49 typedef typename Distance::ElementType ElementType;
50 typedef typename Distance::ResultType DistanceType;
59 virtual void buildIndex() = 0;
69 virtual void knnSearch(
const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists,
int knn,
const SearchParams& params)
78 KNNResultSet<DistanceType> resultSet(knn);
79 for (
size_t i = 0; i < queries.rows; i++) {
80 resultSet.init(indices[i], dists[i]);
81 findNeighbors(resultSet, queries[i], params);
84 KNNUniqueResultSet<DistanceType> resultSet(knn);
85 for (
size_t i = 0; i < queries.rows; i++) {
87 findNeighbors(resultSet, queries[i], params);
88 if (get_param(params,
"sorted",
true)) resultSet.sortAndCopy(indices[i], dists[i], knn);
89 else resultSet.copy(indices[i], dists[i], knn);
103 virtual int radiusSearch(
const Matrix<ElementType>& query, Matrix<int>& indices, Matrix<DistanceType>& dists,
float radius,
const SearchParams& params)
105 if (query.rows != 1) {
106 fprintf(stderr,
"I can only search one feature at a time for range search\n");
113 int* indices_ptr = NULL;
114 DistanceType* dists_ptr = NULL;
115 if (indices.cols > 0) {
116 n = (int)indices.cols;
117 indices_ptr = indices[0];
118 dists_ptr = dists[0];
121 RadiusUniqueResultSet<DistanceType> resultSet((DistanceType)
radius);
123 findNeighbors(resultSet, query[0], params);
125 if (get_param(params,
"sorted",
true)) resultSet.sortAndCopy(indices_ptr, dists_ptr, n);
126 else resultSet.copy(indices_ptr, dists_ptr, n);
129 return (
int)resultSet.size();
136 virtual void saveIndex(FILE* stream) = 0;
142 virtual void loadIndex(FILE* stream) = 0;
147 virtual size_t size()
const = 0;
152 virtual size_t veclen()
const = 0;
157 virtual int usedMemory()
const = 0;
162 virtual flann_algorithm_t getType()
const = 0;
167 virtual IndexParams getParameters()
const = 0;
173 virtual void findNeighbors(ResultSet<DistanceType>&
result,
const ElementType* vec,
const SearchParams& searchParams) = 0;
CvSize size
Definition: core_c.h:112
const CvArr const CvArr CvArr * result
Definition: core_c.h:1423
#define CV_Assert(expr)
Checks a condition at runtime and throws exception if it fails.
Definition: base.hpp:342
CvPoint2D32f float * radius
Definition: imgproc_c.h:534