mirror of
https://github.com/opencv/opencv.git
synced 2024-11-26 04:00:30 +08:00
Merge pull request #2779 from pemmanuelviel:kmeansppSquareDist
This commit is contained in:
commit
3391caf434
@ -872,6 +872,66 @@ typename Distance::ResultType ensureSquareDistance( typename Distance::ResultTyp
|
||||
return dummy( dist );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ...and a template to ensure the user that he will process the normal distance,
|
||||
* and not squared distance, without loosing processing time calling sqrt(ensureSquareDistance)
|
||||
* that will result in doing actually sqrt(dist*dist) for L1 distance for instance.
|
||||
*/
|
||||
template <typename Distance, typename ElementType>
|
||||
struct simpleDistance
|
||||
{
|
||||
typedef typename Distance::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return dist; }
|
||||
};
|
||||
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<L2_Simple<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename L2_Simple<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<L2<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename L2<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<MinkowskiDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename MinkowskiDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<HellingerDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename HellingerDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<ChiSquareDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename ChiSquareDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
|
||||
template <typename Distance>
|
||||
typename Distance::ResultType ensureSimpleDistance( typename Distance::ResultType dist )
|
||||
{
|
||||
typedef typename Distance::ElementType ElementType;
|
||||
|
||||
simpleDistance<Distance, ElementType> dummy;
|
||||
return dummy( dist );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //OPENCV_FLANN_DIST_H_
|
||||
|
Loading…
Reference in New Issue
Block a user