31#ifndef OPENCV_FLANN_BASE_HPP_ 
   32#define OPENCV_FLANN_BASE_HPP_ 
   44#include "all_indices.h" 
   51    explicit FILEScopeGuard(FILE* file) {
 
   68inline void log_verbosity(
int level)
 
   71        Logger::setLevel(level);
 
   78struct SavedIndexParams : 
public IndexParams
 
   82        (* this)[
"algorithm"] = FLANN_INDEX_SAVED;
 
   87template<
typename Distance>
 
   88NNIndex<Distance>* load_saved_index(
const Matrix<typename Distance::ElementType>& dataset, 
const cv::String& 
filename, Distance distance)
 
   90    typedef typename Distance::ElementType ElementType;
 
   96    FILEScopeGuard fscgd(fin);
 
   98    IndexHeader 
header = load_header(fin);
 
   99    if (
header.data_type != Datatype<ElementType>::type()) {
 
  100        FLANN_THROW(
cv::Error::StsError, 
"Datatype of saved index is different than of the one to be created.");
 
  107    params[
"algorithm"] = 
header.index_type;
 
  108    NNIndex<Distance>* nnIndex = create_index_by_type<Distance>(dataset, params, distance);
 
  109    nnIndex->loadIndex(fin);
 
  115template<
typename Distance>
 
  116class Index : 
public NNIndex<Distance>
 
  119    typedef typename Distance::ElementType ElementType;
 
  120    typedef typename Distance::ResultType DistanceType;
 
  122    Index(
const Matrix<ElementType>& features, 
const IndexParams& params, Distance distance = Distance() )
 
  123        :index_params_(params)
 
  125        flann_algorithm_t index_type = get_param<flann_algorithm_t>(params,
"algorithm");
 
  128        if (index_type == FLANN_INDEX_SAVED) {
 
  129            nnIndex_ = load_saved_index<Distance>(features, get_param<cv::String>(params,
"filename"), distance);
 
  133            nnIndex_ = create_index_by_type<Distance>(features, params, distance);
 
  148            nnIndex_->buildIndex();
 
  158        save_header(fout, *nnIndex_);
 
  169        nnIndex_->saveIndex(stream);
 
  178        nnIndex_->loadIndex(stream);
 
  186        return nnIndex_->veclen();
 
  194        return nnIndex_->size();
 
  202        return nnIndex_->getType();
 
  210        return nnIndex_->usedMemory();
 
  219        return nnIndex_->getParameters();
 
  230    void knnSearch(
const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, 
int knn, 
const SearchParams& params) 
CV_OVERRIDE 
  232        nnIndex_->knnSearch(queries, indices, dists, knn, params);
 
  244    int radiusSearch(
const Matrix<ElementType>& query, Matrix<int>& indices, Matrix<DistanceType>& dists, 
float radius, 
const SearchParams& params) 
CV_OVERRIDE 
  246        return nnIndex_->radiusSearch(query, indices, dists, 
radius, params);
 
  252    void findNeighbors(ResultSet<DistanceType>& 
result, 
const ElementType* vec, 
const SearchParams& searchParams) 
CV_OVERRIDE 
  254        nnIndex_->findNeighbors(
result, vec, searchParams);
 
  271        return &index_params_;
 
  276    NNIndex<Distance>* nnIndex_;
 
  280    IndexParams index_params_;
 
  282    Index(
const Index &); 
 
  283    Index& operator=(
const Index &); 
 
  297template <
typename Distance>
 
  298int hierarchicalClustering(
const Matrix<typename Distance::ElementType>& points, Matrix<typename Distance::CentersType>& centers,
 
  299                           const KMeansIndexParams& params, Distance d = Distance())
 
  301    KMeansIndex<Distance> 
kmeans(points, params, d);
 
  304    int clusterNum = 
kmeans.getClusterCenters(centers);
 
CvMat * header
Definition core_c.h:782
CvSize size
Definition core_c.h:112
const char const char ** filename
Definition core_c.h:2630
const CvArr const CvArr CvArr * result
Definition core_c.h:1423
CV_EXPORTS_W double kmeans(InputArray data, int K, InputOutputArray bestLabels, TermCriteria criteria, int attempts, int flags, OutputArray centers=noArray())
Finds centers of clusters and groups input samples around the clusters.
#define CV_DEPRECATED
Definition cvdef.h:450
#define CV_OVERRIDE
Definition cvdef.h:792
int hierarchicalClustering(const Mat &features, Mat ¢ers, const ::cvflann::KMeansIndexParams ¶ms, Distance d=Distance())
Clusters features using hierarchical k-means algorithm.
Definition flann.hpp:584
CvPoint2D32f float * radius
Definition imgproc_c.h:534
@ StsError
unknown /unspecified error
Definition base.hpp:71
int rows
Definition types_c.h:485
int cols
Definition types_c.h:486