mirror of
https://github.com/opencv/opencv.git
synced 2026-09-15 07:29:07 -05:00
Normalize line endings and whitespace
This commit is contained in:
committed by
Andrey Kamaev
parent
69020da607
commit
04384a71e4
@@ -384,7 +384,7 @@ struct HammingLUT
|
||||
*/
|
||||
ResultType operator()(const unsigned char* a, const unsigned char* b, int size) const
|
||||
{
|
||||
static const uchar popCountTable[] =
|
||||
static const uchar popCountTable[] =
|
||||
{
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
@@ -419,7 +419,7 @@ struct HammingLUT2
|
||||
*/
|
||||
ResultType operator()(const unsigned char* a, const unsigned char* b, size_t size) const
|
||||
{
|
||||
static const uchar popCountTable[] =
|
||||
static const uchar popCountTable[] =
|
||||
{
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
@@ -549,9 +549,9 @@ struct Hamming2
|
||||
ResultType result = 0;
|
||||
size /= (sizeof(uint32_t)/sizeof(unsigned char));
|
||||
for(size_t i = 0; i < size; ++i ) {
|
||||
result += popcnt32(*pa ^ *pb);
|
||||
++pa;
|
||||
++pb;
|
||||
result += popcnt32(*pa ^ *pb);
|
||||
++pa;
|
||||
++pb;
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
|
||||
@@ -93,7 +93,7 @@ using ::cvflann::KL_Divergence;
|
||||
|
||||
|
||||
template <typename Distance>
|
||||
class GenericIndex
|
||||
class GenericIndex
|
||||
{
|
||||
public:
|
||||
typedef typename Distance::ElementType ElementType;
|
||||
@@ -103,13 +103,13 @@ public:
|
||||
|
||||
~GenericIndex();
|
||||
|
||||
void knnSearch(const vector<ElementType>& query, vector<int>& indices,
|
||||
void knnSearch(const vector<ElementType>& query, vector<int>& indices,
|
||||
vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& params);
|
||||
void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& params);
|
||||
|
||||
int radiusSearch(const vector<ElementType>& query, vector<int>& indices,
|
||||
int radiusSearch(const vector<ElementType>& query, vector<int>& indices,
|
||||
vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& params);
|
||||
int radiusSearch(const Mat& query, Mat& indices, Mat& dists,
|
||||
int radiusSearch(const Mat& query, Mat& indices, Mat& dists,
|
||||
DistanceType radius, const ::cvflann::SearchParams& params);
|
||||
|
||||
void save(std::string filename) { nnIndex->save(filename); }
|
||||
@@ -134,7 +134,7 @@ private:
|
||||
"(cv::flann::Index always uses L2). You should create the index templated on the distance, "\
|
||||
"for example for L1 distance use: GenericIndex< L1<float> > \n"); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename Distance>
|
||||
GenericIndex<Distance>::GenericIndex(const Mat& dataset, const ::cvflann::IndexParams& params, Distance distance)
|
||||
@@ -142,11 +142,11 @@ GenericIndex<Distance>::GenericIndex(const Mat& dataset, const ::cvflann::IndexP
|
||||
CV_Assert(dataset.type() == CvType<ElementType>::type());
|
||||
CV_Assert(dataset.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_dataset((ElementType*)dataset.ptr<ElementType>(0), dataset.rows, dataset.cols);
|
||||
|
||||
|
||||
nnIndex = new ::cvflann::Index<Distance>(m_dataset, params, distance);
|
||||
|
||||
|
||||
FLANN_DISTANCE_CHECK
|
||||
|
||||
|
||||
nnIndex->buildIndex();
|
||||
}
|
||||
|
||||
@@ -175,17 +175,17 @@ void GenericIndex<Distance>::knnSearch(const Mat& queries, Mat& indices, Mat& di
|
||||
CV_Assert(queries.type() == CvType<ElementType>::type());
|
||||
CV_Assert(queries.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_queries((ElementType*)queries.ptr<ElementType>(0), queries.rows, queries.cols);
|
||||
|
||||
|
||||
CV_Assert(indices.type() == CV_32S);
|
||||
CV_Assert(indices.isContinuous());
|
||||
::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
|
||||
|
||||
|
||||
CV_Assert(dists.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(dists.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
|
||||
|
||||
FLANN_DISTANCE_CHECK
|
||||
|
||||
|
||||
nnIndex->knnSearch(m_queries,m_indices,m_dists,knn, searchParams);
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ int GenericIndex<Distance>::radiusSearch(const vector<ElementType>& query, vecto
|
||||
::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
|
||||
|
||||
FLANN_DISTANCE_CHECK
|
||||
|
||||
|
||||
return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
}
|
||||
|
||||
@@ -207,17 +207,17 @@ int GenericIndex<Distance>::radiusSearch(const Mat& query, Mat& indices, Mat& di
|
||||
CV_Assert(query.type() == CvType<ElementType>::type());
|
||||
CV_Assert(query.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)query.ptr<ElementType>(0), query.rows, query.cols);
|
||||
|
||||
|
||||
CV_Assert(indices.type() == CV_32S);
|
||||
CV_Assert(indices.isContinuous());
|
||||
::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
|
||||
|
||||
|
||||
CV_Assert(dists.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(dists.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
|
||||
|
||||
|
||||
FLANN_DISTANCE_CHECK
|
||||
|
||||
|
||||
return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
}
|
||||
|
||||
@@ -234,45 +234,45 @@ public:
|
||||
typedef typename L2<T>::ElementType ElementType;
|
||||
typedef typename L2<T>::ResultType DistanceType;
|
||||
|
||||
Index_(const Mat& features, const ::cvflann::IndexParams& params);
|
||||
Index_(const Mat& features, const ::cvflann::IndexParams& params);
|
||||
|
||||
~Index_();
|
||||
~Index_();
|
||||
|
||||
void knnSearch(const vector<ElementType>& query, vector<int>& indices, vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& params);
|
||||
void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& params);
|
||||
void knnSearch(const vector<ElementType>& query, vector<int>& indices, vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& params);
|
||||
void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& params);
|
||||
|
||||
int radiusSearch(const vector<ElementType>& query, vector<int>& indices, vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& params);
|
||||
int radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& params);
|
||||
int radiusSearch(const vector<ElementType>& query, vector<int>& indices, vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& params);
|
||||
int radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& params);
|
||||
|
||||
void save(std::string filename)
|
||||
{
|
||||
void save(std::string filename)
|
||||
{
|
||||
if (nnIndex_L1) nnIndex_L1->save(filename);
|
||||
if (nnIndex_L2) nnIndex_L2->save(filename);
|
||||
}
|
||||
|
||||
int veclen() const
|
||||
{
|
||||
int veclen() const
|
||||
{
|
||||
if (nnIndex_L1) return nnIndex_L1->veclen();
|
||||
if (nnIndex_L2) return nnIndex_L2->veclen();
|
||||
if (nnIndex_L2) return nnIndex_L2->veclen();
|
||||
}
|
||||
|
||||
int size() const
|
||||
{
|
||||
int size() const
|
||||
{
|
||||
if (nnIndex_L1) return nnIndex_L1->size();
|
||||
if (nnIndex_L2) return nnIndex_L2->size();
|
||||
if (nnIndex_L2) return nnIndex_L2->size();
|
||||
}
|
||||
|
||||
::cvflann::IndexParams getParameters()
|
||||
{
|
||||
::cvflann::IndexParams getParameters()
|
||||
{
|
||||
if (nnIndex_L1) return nnIndex_L1->getParameters();
|
||||
if (nnIndex_L2) return nnIndex_L2->getParameters();
|
||||
|
||||
|
||||
}
|
||||
|
||||
FLANN_DEPRECATED const ::cvflann::IndexParams* getIndexParameters()
|
||||
{
|
||||
FLANN_DEPRECATED const ::cvflann::IndexParams* getIndexParameters()
|
||||
{
|
||||
if (nnIndex_L1) return nnIndex_L1->getIndexParameters();
|
||||
if (nnIndex_L2) return nnIndex_L2->getIndexParameters();
|
||||
if (nnIndex_L2) return nnIndex_L2->getIndexParameters();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -290,18 +290,18 @@ template <typename T>
|
||||
Index_<T>::Index_(const Mat& dataset, const ::cvflann::IndexParams& params)
|
||||
{
|
||||
printf("[WARNING] The cv::flann::Index_<T> class is deperecated, use cv::flann::GenericIndex<Distance> instead\n");
|
||||
|
||||
|
||||
CV_Assert(dataset.type() == CvType<ElementType>::type());
|
||||
CV_Assert(dataset.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_dataset((ElementType*)dataset.ptr<ElementType>(0), dataset.rows, dataset.cols);
|
||||
|
||||
|
||||
if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) {
|
||||
nnIndex_L1 = NULL;
|
||||
nnIndex_L2 = new ::cvflann::Index< L2<ElementType> >(m_dataset, params);
|
||||
}
|
||||
else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) {
|
||||
nnIndex_L1 = new ::cvflann::Index< L1<ElementType> >(m_dataset, params);
|
||||
nnIndex_L2 = NULL;
|
||||
nnIndex_L2 = NULL;
|
||||
}
|
||||
else {
|
||||
printf("[ERROR] cv::flann::Index_<T> only provides backwards compatibility for the L1 and L2 distances. "
|
||||
@@ -325,7 +325,7 @@ void Index_<T>::knnSearch(const vector<ElementType>& query, vector<int>& indices
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
|
||||
::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
|
||||
::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
|
||||
|
||||
|
||||
if (nnIndex_L1) nnIndex_L1->knnSearch(m_query,m_indices,m_dists,knn,searchParams);
|
||||
if (nnIndex_L2) nnIndex_L2->knnSearch(m_query,m_indices,m_dists,knn,searchParams);
|
||||
}
|
||||
@@ -337,11 +337,11 @@ void Index_<T>::knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn,
|
||||
CV_Assert(queries.type() == CvType<ElementType>::type());
|
||||
CV_Assert(queries.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_queries((ElementType*)queries.ptr<ElementType>(0), queries.rows, queries.cols);
|
||||
|
||||
|
||||
CV_Assert(indices.type() == CV_32S);
|
||||
CV_Assert(indices.isContinuous());
|
||||
::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
|
||||
|
||||
|
||||
CV_Assert(dists.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(dists.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
|
||||
@@ -356,7 +356,7 @@ int Index_<T>::radiusSearch(const vector<ElementType>& query, vector<int>& indic
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
|
||||
::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
|
||||
::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
|
||||
|
||||
|
||||
if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
}
|
||||
@@ -367,15 +367,15 @@ int Index_<T>::radiusSearch(const Mat& query, Mat& indices, Mat& dists, Distance
|
||||
CV_Assert(query.type() == CvType<ElementType>::type());
|
||||
CV_Assert(query.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)query.ptr<ElementType>(0), query.rows, query.cols);
|
||||
|
||||
|
||||
CV_Assert(indices.type() == CV_32S);
|
||||
CV_Assert(indices.isContinuous());
|
||||
::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
|
||||
|
||||
|
||||
CV_Assert(dists.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(dists.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
|
||||
|
||||
|
||||
if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
}
|
||||
@@ -387,11 +387,11 @@ int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::K
|
||||
{
|
||||
typedef typename Distance::ElementType ElementType;
|
||||
typedef typename Distance::ResultType DistanceType;
|
||||
|
||||
|
||||
CV_Assert(features.type() == CvType<ElementType>::type());
|
||||
CV_Assert(features.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_features((ElementType*)features.ptr<ElementType>(0), features.rows, features.cols);
|
||||
|
||||
|
||||
CV_Assert(centers.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(centers.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_centers((DistanceType*)centers.ptr<DistanceType>(0), centers.rows, centers.cols);
|
||||
@@ -405,7 +405,7 @@ FLANN_DEPRECATED int hierarchicalClustering(const Mat& features, Mat& centers, c
|
||||
{
|
||||
printf("[WARNING] cv::flann::hierarchicalClustering<ELEM_TYPE,DIST_TYPE> is deprecated, use "
|
||||
"cv::flann::hierarchicalClustering<Distance> instead\n");
|
||||
|
||||
|
||||
if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) {
|
||||
return hierarchicalClustering< L2<ELEM_TYPE> >(features, centers, params);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ private:
|
||||
int best_index = -1;
|
||||
DistanceType best_val = 0;
|
||||
for (int j=0; j<n; ++j) {
|
||||
DistanceType dist = distance(dataset[centers[0]],dataset[dsindices[j]],dataset.cols);
|
||||
DistanceType dist = distance(dataset[centers[0]],dataset[dsindices[j]],dataset.cols);
|
||||
for (int i=1; i<index; ++i) {
|
||||
DistanceType tmp_dist = distance(dataset[centers[i]],dataset[dsindices[j]],dataset.cols);
|
||||
if (tmp_dist<dist) {
|
||||
|
||||
@@ -253,18 +253,18 @@ private:
|
||||
/*--------------------- Internal Data Structures --------------------------*/
|
||||
struct Node
|
||||
{
|
||||
/**
|
||||
* Indices of points in leaf node
|
||||
*/
|
||||
int left, right;
|
||||
/**
|
||||
* Dimension used for subdivision.
|
||||
*/
|
||||
int divfeat;
|
||||
/**
|
||||
* The values used for subdivision.
|
||||
*/
|
||||
DistanceType divlow, divhigh;
|
||||
/**
|
||||
* Indices of points in leaf node
|
||||
*/
|
||||
int left, right;
|
||||
/**
|
||||
* Dimension used for subdivision.
|
||||
*/
|
||||
int divfeat;
|
||||
/**
|
||||
* The values used for subdivision.
|
||||
*/
|
||||
DistanceType divlow, divhigh;
|
||||
/**
|
||||
* The child nodes.
|
||||
*/
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
Distance d = Distance()) :
|
||||
dataset_(input_data), index_params_(params), distance_(d)
|
||||
{
|
||||
// cv::flann::IndexParams sets integer params as 'int', so it is used with get_param
|
||||
// cv::flann::IndexParams sets integer params as 'int', so it is used with get_param
|
||||
// in place of 'unsigned int'
|
||||
table_number_ = (unsigned int)get_param<int>(index_params_,"table_number",12);
|
||||
key_size_ = (unsigned int)get_param<int>(index_params_,"key_size",20);
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
|
||||
namespace flann
|
||||
{
|
||||
|
||||
@@ -58,31 +58,31 @@ struct CV_EXPORTS IndexParams
|
||||
{
|
||||
IndexParams();
|
||||
~IndexParams();
|
||||
|
||||
|
||||
std::string getString(const std::string& key, const std::string& defaultVal=std::string()) const;
|
||||
int getInt(const std::string& key, int defaultVal=-1) const;
|
||||
double getDouble(const std::string& key, double defaultVal=-1) const;
|
||||
|
||||
|
||||
void setString(const std::string& key, const std::string& value);
|
||||
void setInt(const std::string& key, int value);
|
||||
void setDouble(const std::string& key, double value);
|
||||
void setFloat(const std::string& key, float value);
|
||||
void setBool(const std::string& key, bool value);
|
||||
void setAlgorithm(int value);
|
||||
|
||||
|
||||
void getAll(std::vector<std::string>& names,
|
||||
std::vector<int>& types,
|
||||
std::vector<std::string>& strValues,
|
||||
std::vector<double>& numValues) const;
|
||||
|
||||
|
||||
void* params;
|
||||
};
|
||||
};
|
||||
|
||||
struct CV_EXPORTS KDTreeIndexParams : public IndexParams
|
||||
{
|
||||
KDTreeIndexParams(int trees=4);
|
||||
};
|
||||
|
||||
|
||||
struct CV_EXPORTS LinearIndexParams : public IndexParams
|
||||
{
|
||||
LinearIndexParams();
|
||||
@@ -99,10 +99,10 @@ struct CV_EXPORTS AutotunedIndexParams : public IndexParams
|
||||
AutotunedIndexParams(float target_precision = 0.8, float build_weight = 0.01,
|
||||
float memory_weight = 0, float sample_fraction = 0.1);
|
||||
};
|
||||
|
||||
|
||||
struct CV_EXPORTS HierarchicalClusteringIndexParams : public IndexParams
|
||||
{
|
||||
HierarchicalClusteringIndexParams(int branching = 32,
|
||||
HierarchicalClusteringIndexParams(int branching = 32,
|
||||
cvflann::flann_centers_init_t centers_init = cvflann::FLANN_CENTERS_RANDOM, int trees = 4, int leaf_size = 100 );
|
||||
};
|
||||
|
||||
@@ -116,45 +116,45 @@ struct CV_EXPORTS LshIndexParams : public IndexParams
|
||||
{
|
||||
LshIndexParams(int table_number, int key_size, int multi_probe_level);
|
||||
};
|
||||
|
||||
|
||||
struct CV_EXPORTS SavedIndexParams : public IndexParams
|
||||
{
|
||||
SavedIndexParams(const std::string& filename);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
struct CV_EXPORTS SearchParams : public IndexParams
|
||||
{
|
||||
SearchParams( int checks = 32, float eps = 0, bool sorted = true );
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
class CV_EXPORTS_W Index
|
||||
{
|
||||
public:
|
||||
CV_WRAP Index();
|
||||
CV_WRAP Index(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2);
|
||||
virtual ~Index();
|
||||
|
||||
|
||||
CV_WRAP virtual void build(InputArray features, const IndexParams& params, cvflann::flann_distance_t distType=cvflann::FLANN_DIST_L2);
|
||||
CV_WRAP virtual void knnSearch(InputArray query, OutputArray indices,
|
||||
CV_WRAP virtual void knnSearch(InputArray query, OutputArray indices,
|
||||
OutputArray dists, int knn, const SearchParams& params=SearchParams());
|
||||
|
||||
|
||||
CV_WRAP virtual int radiusSearch(InputArray query, OutputArray indices,
|
||||
OutputArray dists, double radius, int maxResults,
|
||||
const SearchParams& params=SearchParams());
|
||||
|
||||
|
||||
CV_WRAP virtual void save(const std::string& filename) const;
|
||||
CV_WRAP virtual bool load(InputArray features, const std::string& filename);
|
||||
CV_WRAP virtual void release();
|
||||
CV_WRAP cvflann::flann_distance_t getDistance() const;
|
||||
CV_WRAP cvflann::flann_algorithm_t getAlgorithm() const;
|
||||
|
||||
|
||||
protected:
|
||||
cvflann::flann_distance_t distType;
|
||||
cvflann::flann_algorithm_t algo;
|
||||
int featureType;
|
||||
void* index;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace cv::flann
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
@@ -14,12 +14,12 @@ cv::flann::IndexParams::~IndexParams()
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
|
||||
namespace flann
|
||||
{
|
||||
|
||||
using namespace cvflann;
|
||||
|
||||
|
||||
IndexParams::IndexParams()
|
||||
{
|
||||
params = new ::cvflann::IndexParams();
|
||||
@@ -40,24 +40,24 @@ void setParam(IndexParams& _p, const std::string& key, const T& value)
|
||||
{
|
||||
::cvflann::IndexParams& p = get_params(_p);
|
||||
p[key] = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string IndexParams::getString(const std::string& key, const std::string& defaultVal) const
|
||||
{
|
||||
return getParam(*this, key, defaultVal);
|
||||
}
|
||||
|
||||
|
||||
int IndexParams::getInt(const std::string& key, int defaultVal) const
|
||||
{
|
||||
return getParam(*this, key, defaultVal);
|
||||
}
|
||||
|
||||
|
||||
double IndexParams::getDouble(const std::string& key, double defaultVal) const
|
||||
{
|
||||
return getParam(*this, key, defaultVal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IndexParams::setString(const std::string& key, const std::string& value)
|
||||
{
|
||||
setParam(*this, key, value);
|
||||
@@ -87,7 +87,7 @@ void IndexParams::setAlgorithm(int value)
|
||||
{
|
||||
setParam(*this, "algorithm", (cvflann::flann_algorithm_t)value);
|
||||
}
|
||||
|
||||
|
||||
void IndexParams::getAll(std::vector<std::string>& names,
|
||||
std::vector<int>& types,
|
||||
std::vector<std::string>& strValues,
|
||||
@@ -97,10 +97,10 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
types.clear();
|
||||
strValues.clear();
|
||||
numValues.clear();
|
||||
|
||||
|
||||
::cvflann::IndexParams& p = get_params(*this);
|
||||
::cvflann::IndexParams::const_iterator it = p.begin(), it_end = p.end();
|
||||
|
||||
|
||||
for( ; it != it_end; ++it )
|
||||
{
|
||||
names.push_back(it->first);
|
||||
@@ -110,18 +110,18 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
types.push_back(CV_USRTYPE1);
|
||||
strValues.push_back(val);
|
||||
numValues.push_back(-1);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
|
||||
|
||||
strValues.push_back(it->second.type().name());
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
double val = it->second.cast<double>();
|
||||
types.push_back( CV_64F );
|
||||
numValues.push_back(val);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
@@ -129,7 +129,7 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
float val = it->second.cast<float>();
|
||||
types.push_back( CV_32F );
|
||||
numValues.push_back(val);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
@@ -137,7 +137,7 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
int val = it->second.cast<int>();
|
||||
types.push_back( CV_32S );
|
||||
numValues.push_back(val);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
@@ -145,7 +145,7 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
short val = it->second.cast<short>();
|
||||
types.push_back( CV_16S );
|
||||
numValues.push_back(val);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
@@ -153,7 +153,7 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
ushort val = it->second.cast<ushort>();
|
||||
types.push_back( CV_16U );
|
||||
numValues.push_back(val);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
@@ -161,7 +161,7 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
char val = it->second.cast<char>();
|
||||
types.push_back( CV_8S );
|
||||
numValues.push_back(val);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
@@ -169,7 +169,7 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
uchar val = it->second.cast<uchar>();
|
||||
types.push_back( CV_8U );
|
||||
numValues.push_back(val);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
@@ -177,7 +177,7 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
bool val = it->second.cast<bool>();
|
||||
types.push_back( CV_MAKETYPE(CV_USRTYPE1,2) );
|
||||
numValues.push_back(val);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
@@ -185,7 +185,7 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
cvflann::flann_algorithm_t val = it->second.cast<cvflann::flann_algorithm_t>();
|
||||
types.push_back( CV_MAKETYPE(CV_USRTYPE1,3) );
|
||||
numValues.push_back(val);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
catch (...) {}
|
||||
|
||||
@@ -194,8 +194,8 @@ void IndexParams::getAll(std::vector<std::string>& names,
|
||||
numValues.push_back(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
KDTreeIndexParams::KDTreeIndexParams(int trees)
|
||||
{
|
||||
::cvflann::IndexParams& p = get_params(*this);
|
||||
@@ -225,7 +225,7 @@ CompositeIndexParams::CompositeIndexParams(int trees, int branching, int iterati
|
||||
// cluster boundary index. Used when searching the kmeans tree
|
||||
p["cb_index"] = cb_index;
|
||||
}
|
||||
|
||||
|
||||
AutotunedIndexParams::AutotunedIndexParams(float target_precision, float build_weight,
|
||||
float memory_weight, float sample_fraction)
|
||||
{
|
||||
@@ -240,7 +240,7 @@ AutotunedIndexParams::AutotunedIndexParams(float target_precision, float build_w
|
||||
// what fraction of the dataset to use for autotuning
|
||||
p["sample_fraction"] = sample_fraction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
KMeansIndexParams::KMeansIndexParams(int branching, int iterations,
|
||||
flann_centers_init_t centers_init, float cb_index )
|
||||
@@ -272,7 +272,7 @@ HierarchicalClusteringIndexParams::HierarchicalClusteringIndexParams(int branchi
|
||||
// maximum leaf size
|
||||
p["leaf_size"] = leaf_size;
|
||||
}
|
||||
|
||||
|
||||
LshIndexParams::LshIndexParams(int table_number, int key_size, int multi_probe_level)
|
||||
{
|
||||
::cvflann::IndexParams& p = get_params(*this);
|
||||
@@ -283,30 +283,30 @@ LshIndexParams::LshIndexParams(int table_number, int key_size, int multi_probe_l
|
||||
p["key_size"] = key_size;
|
||||
// Number of levels to use in multi-probe (0 for standard LSH)
|
||||
p["multi_probe_level"] = multi_probe_level;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SavedIndexParams::SavedIndexParams(const std::string& _filename)
|
||||
{
|
||||
std::string filename = _filename;
|
||||
::cvflann::IndexParams& p = get_params(*this);
|
||||
|
||||
|
||||
p["algorithm"] = FLANN_INDEX_SAVED;
|
||||
p["filename"] = filename;
|
||||
}
|
||||
|
||||
|
||||
SearchParams::SearchParams( int checks, float eps, bool sorted )
|
||||
{
|
||||
::cvflann::IndexParams& p = get_params(*this);
|
||||
|
||||
|
||||
// how many leafs to visit when searching for neighbours (-1 for unlimited)
|
||||
p["checks"] = checks;
|
||||
// search for eps-approximate neighbours (default: 0)
|
||||
p["eps"] = eps;
|
||||
// only for radius search, require neighbours sorted by distance (default: true)
|
||||
p["sorted"] = sorted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename Distance, typename IndexType> void
|
||||
buildIndex_(void*& index, const Mat& data, const IndexParams& params, const Distance& dist = Distance())
|
||||
{
|
||||
@@ -315,7 +315,7 @@ buildIndex_(void*& index, const Mat& data, const IndexParams& params, const Dist
|
||||
CV_Error_(CV_StsUnsupportedFormat, ("type=%d\n", data.type()));
|
||||
if(!data.isContinuous())
|
||||
CV_Error(CV_StsBadArg, "Only continuous arrays are supported");
|
||||
|
||||
|
||||
::cvflann::Matrix<ElementType> dataset((ElementType*)data.data, data.rows, data.cols);
|
||||
IndexType* _index = new IndexType(dataset, get_params(params), dist);
|
||||
_index->buildIndex();
|
||||
@@ -341,7 +341,7 @@ Index::Index()
|
||||
algo = FLANN_INDEX_LINEAR;
|
||||
distType = FLANN_DIST_L2;
|
||||
}
|
||||
|
||||
|
||||
Index::Index(InputArray _data, const IndexParams& params, flann_distance_t _distType)
|
||||
{
|
||||
index = 0;
|
||||
@@ -350,7 +350,7 @@ Index::Index(InputArray _data, const IndexParams& params, flann_distance_t _dist
|
||||
distType = FLANN_DIST_L2;
|
||||
build(_data, params, _distType);
|
||||
}
|
||||
|
||||
|
||||
void Index::build(InputArray _data, const IndexParams& params, flann_distance_t _distType)
|
||||
{
|
||||
release();
|
||||
@@ -360,13 +360,13 @@ void Index::build(InputArray _data, const IndexParams& params, flann_distance_t
|
||||
load(_data, getParam<std::string>(params, "filename", std::string()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Mat data = _data.getMat();
|
||||
index = 0;
|
||||
featureType = data.type();
|
||||
distType = _distType;
|
||||
|
||||
if ( algo == FLANN_INDEX_LSH)
|
||||
|
||||
if ( algo == FLANN_INDEX_LSH)
|
||||
{
|
||||
distType = FLANN_DIST_HAMMING;
|
||||
}
|
||||
@@ -413,17 +413,17 @@ template<typename Distance> void deleteIndex(void* index)
|
||||
{
|
||||
deleteIndex_< ::cvflann::Index<Distance> >(index);
|
||||
}
|
||||
|
||||
|
||||
Index::~Index()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
|
||||
void Index::release()
|
||||
{
|
||||
if( !index )
|
||||
return;
|
||||
|
||||
|
||||
switch( distType )
|
||||
{
|
||||
case FLANN_DIST_HAMMING:
|
||||
@@ -468,15 +468,15 @@ void runKnnSearch_(void* index, const Mat& query, Mat& indices, Mat& dists,
|
||||
int dtype = DataType<DistanceType>::type;
|
||||
CV_Assert(query.type() == type && indices.type() == CV_32S && dists.type() == dtype);
|
||||
CV_Assert(query.isContinuous() && indices.isContinuous() && dists.isContinuous());
|
||||
|
||||
|
||||
::cvflann::Matrix<ElementType> _query((ElementType*)query.data, query.rows, query.cols);
|
||||
::cvflann::Matrix<int> _indices((int*)indices.data, indices.rows, indices.cols);
|
||||
::cvflann::Matrix<DistanceType> _dists((DistanceType*)dists.data, dists.rows, dists.cols);
|
||||
|
||||
|
||||
((IndexType*)index)->knnSearch(_query, _indices, _dists, knn,
|
||||
(const ::cvflann::SearchParams&)get_params(params));
|
||||
}
|
||||
|
||||
|
||||
template<typename Distance>
|
||||
void runKnnSearch(void* index, const Mat& query, Mat& indices, Mat& dists,
|
||||
int knn, const SearchParams& params)
|
||||
@@ -494,11 +494,11 @@ int runRadiusSearch_(void* index, const Mat& query, Mat& indices, Mat& dists,
|
||||
int dtype = DataType<DistanceType>::type;
|
||||
CV_Assert(query.type() == type && indices.type() == CV_32S && dists.type() == dtype);
|
||||
CV_Assert(query.isContinuous() && indices.isContinuous() && dists.isContinuous());
|
||||
|
||||
|
||||
::cvflann::Matrix<ElementType> _query((ElementType*)query.data, query.rows, query.cols);
|
||||
::cvflann::Matrix<int> _indices((int*)indices.data, indices.rows, indices.cols);
|
||||
::cvflann::Matrix<DistanceType> _dists((DistanceType*)dists.data, dists.rows, dists.cols);
|
||||
|
||||
|
||||
return ((IndexType*)index)->radiusSearch(_query, _indices, _dists,
|
||||
saturate_cast<DistanceType>(radius),
|
||||
(const ::cvflann::SearchParams&)get_params(params));
|
||||
@@ -510,8 +510,8 @@ int runRadiusSearch(void* index, const Mat& query, Mat& indices, Mat& dists,
|
||||
{
|
||||
return runRadiusSearch_<Distance, ::cvflann::Index<Distance> >(index, query, indices, dists, radius, params);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void createIndicesDists(OutputArray _indices, OutputArray _dists,
|
||||
Mat& indices, Mat& dists, int rows,
|
||||
int minCols, int maxCols, int dtype)
|
||||
@@ -530,7 +530,7 @@ static void createIndicesDists(OutputArray _indices, OutputArray _dists,
|
||||
}
|
||||
else
|
||||
indices.create( rows, minCols, CV_32S );
|
||||
|
||||
|
||||
if( _dists.needed() )
|
||||
{
|
||||
dists = _dists.getMat();
|
||||
@@ -547,15 +547,15 @@ static void createIndicesDists(OutputArray _indices, OutputArray _dists,
|
||||
dists.create( rows, minCols, dtype );
|
||||
}
|
||||
|
||||
|
||||
void Index::knnSearch(InputArray _query, OutputArray _indices,
|
||||
|
||||
void Index::knnSearch(InputArray _query, OutputArray _indices,
|
||||
OutputArray _dists, int knn, const SearchParams& params)
|
||||
{
|
||||
Mat query = _query.getMat(), indices, dists;
|
||||
int dtype = distType == FLANN_DIST_HAMMING ? CV_32S : CV_32F;
|
||||
|
||||
|
||||
createIndicesDists( _indices, _dists, indices, dists, query.rows, knn, knn, dtype );
|
||||
|
||||
|
||||
switch( distType )
|
||||
{
|
||||
case FLANN_DIST_HAMMING:
|
||||
@@ -588,7 +588,7 @@ void Index::knnSearch(InputArray _query, OutputArray _indices,
|
||||
CV_Error(CV_StsBadArg, "Unknown/unsupported distance type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Index::radiusSearch(InputArray _query, OutputArray _indices,
|
||||
OutputArray _dists, double radius, int maxResults,
|
||||
const SearchParams& params)
|
||||
@@ -597,10 +597,10 @@ int Index::radiusSearch(InputArray _query, OutputArray _indices,
|
||||
int dtype = distType == FLANN_DIST_HAMMING ? CV_32S : CV_32F;
|
||||
CV_Assert( maxResults > 0 );
|
||||
createIndicesDists( _indices, _dists, indices, dists, query.rows, maxResults, INT_MAX, dtype );
|
||||
|
||||
|
||||
if( algo == FLANN_INDEX_LSH )
|
||||
CV_Error( CV_StsNotImplemented, "LSH index does not support radiusSearch operation" );
|
||||
|
||||
|
||||
switch( distType )
|
||||
{
|
||||
case FLANN_DIST_HAMMING:
|
||||
@@ -632,7 +632,7 @@ flann_distance_t Index::getDistance() const
|
||||
{
|
||||
return distType;
|
||||
}
|
||||
|
||||
|
||||
flann_algorithm_t Index::getAlgorithm() const
|
||||
{
|
||||
return algo;
|
||||
@@ -652,14 +652,14 @@ template<typename IndexType> void saveIndex_(const Index* index0, const void* in
|
||||
template<typename Distance> void saveIndex(const Index* index0, const void* index, FILE* fout)
|
||||
{
|
||||
saveIndex_< ::cvflann::Index<Distance> >(index0, index, fout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Index::save(const std::string& filename) const
|
||||
{
|
||||
FILE* fout = fopen(filename.c_str(), "wb");
|
||||
if (fout == NULL)
|
||||
CV_Error_( CV_StsError, ("Can not open file %s for writing FLANN index\n", filename.c_str()) );
|
||||
|
||||
|
||||
switch( distType )
|
||||
{
|
||||
case FLANN_DIST_HAMMING:
|
||||
@@ -703,9 +703,9 @@ bool loadIndex_(Index* index0, void*& index, const Mat& data, FILE* fin, const D
|
||||
{
|
||||
typedef typename Distance::ElementType ElementType;
|
||||
CV_Assert(DataType<ElementType>::type == data.type() && data.isContinuous());
|
||||
|
||||
|
||||
::cvflann::Matrix<ElementType> dataset((ElementType*)data.data, data.rows, data.cols);
|
||||
|
||||
|
||||
::cvflann::IndexParams params;
|
||||
params["algorithm"] = index0->getAlgorithm();
|
||||
IndexType* _index = new IndexType(dataset, params, dist);
|
||||
@@ -718,8 +718,8 @@ template<typename Distance>
|
||||
bool loadIndex(Index* index0, void*& index, const Mat& data, FILE* fin, const Distance& dist=Distance())
|
||||
{
|
||||
return loadIndex_<Distance, ::cvflann::Index<Distance> >(index0, index, data, fin, dist);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Index::load(InputArray _data, const std::string& filename)
|
||||
{
|
||||
Mat data = _data.getMat();
|
||||
@@ -728,7 +728,7 @@ bool Index::load(InputArray _data, const std::string& filename)
|
||||
FILE* fin = fopen(filename.c_str(), "rb");
|
||||
if (fin == NULL)
|
||||
return false;
|
||||
|
||||
|
||||
::cvflann::IndexHeader header = ::cvflann::load_header(fin);
|
||||
algo = header.index_type;
|
||||
featureType = header.data_type == FLANN_UINT8 ? CV_8U :
|
||||
@@ -738,7 +738,7 @@ bool Index::load(InputArray _data, const std::string& filename)
|
||||
header.data_type == FLANN_INT32 ? CV_32S :
|
||||
header.data_type == FLANN_FLOAT32 ? CV_32F :
|
||||
header.data_type == FLANN_FLOAT64 ? CV_64F : -1;
|
||||
|
||||
|
||||
if( (int)header.rows != data.rows || (int)header.cols != data.cols ||
|
||||
featureType != data.type() )
|
||||
{
|
||||
@@ -747,19 +747,19 @@ bool Index::load(InputArray _data, const std::string& filename)
|
||||
fclose(fin);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int idistType = 0;
|
||||
::cvflann::load_value(fin, idistType);
|
||||
distType = (flann_distance_t)idistType;
|
||||
|
||||
if( !((distType == FLANN_DIST_HAMMING && featureType == CV_8U) ||
|
||||
if( !((distType == FLANN_DIST_HAMMING && featureType == CV_8U) ||
|
||||
(distType != FLANN_DIST_HAMMING && featureType == CV_32F)) )
|
||||
{
|
||||
fprintf(stderr, "Reading FLANN index error: unsupported feature type %d for the index type %d\n", featureType, algo);
|
||||
fclose(fin);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
switch( distType )
|
||||
{
|
||||
case FLANN_DIST_HAMMING:
|
||||
@@ -797,7 +797,7 @@ bool Index::load(InputArray _data, const std::string& filename)
|
||||
fclose(fin);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#ifndef _OPENCV_FLANN_PRECOMP_HPP_
|
||||
#define _OPENCV_FLANN_PRECOMP_HPP_
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
# include "cvconfig.h"
|
||||
#endif
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "opencv2/flann/miniflann.hpp"
|
||||
#include "opencv2/flann/dist.h"
|
||||
#include "opencv2/flann/index_testing.h"
|
||||
#include "opencv2/flann/params.h"
|
||||
#include "opencv2/flann/saving.h"
|
||||
#include "opencv2/flann/general.h"
|
||||
#include "opencv2/flann/dummy.h"
|
||||
|
||||
// index types
|
||||
#include "opencv2/flann/all_indices.h"
|
||||
#include "opencv2/flann/flann_base.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _OPENCV_FLANN_PRECOMP_HPP_
|
||||
#define _OPENCV_FLANN_PRECOMP_HPP_
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdarg>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
# include "cvconfig.h"
|
||||
#endif
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "opencv2/flann/miniflann.hpp"
|
||||
#include "opencv2/flann/dist.h"
|
||||
#include "opencv2/flann/index_testing.h"
|
||||
#include "opencv2/flann/params.h"
|
||||
#include "opencv2/flann/saving.h"
|
||||
#include "opencv2/flann/general.h"
|
||||
#include "opencv2/flann/dummy.h"
|
||||
|
||||
// index types
|
||||
#include "opencv2/flann/all_indices.h"
|
||||
#include "opencv2/flann/flann_base.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user