From 3bd364fce3b87e3218630f9eb9cd6b1db11ff80a Mon Sep 17 00:00:00 2001 From: Adil Ibragimov Date: Fri, 25 Apr 2014 17:37:31 +0400 Subject: [PATCH] fixing accum_dist and operator() mismatching for HellingerDistance and KL_Divergence --- modules/flann/include/opencv2/flann/dist.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/flann/include/opencv2/flann/dist.h b/modules/flann/include/opencv2/flann/dist.h index 6a03b48a1..5d941e67f 100644 --- a/modules/flann/include/opencv2/flann/dist.h +++ b/modules/flann/include/opencv2/flann/dist.h @@ -595,7 +595,7 @@ struct HellingerDistance typedef typename Accumulator::Type ResultType; /** - * Compute the histogram intersection distance + * Compute the Hellinger distance */ template ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const @@ -628,7 +628,8 @@ struct HellingerDistance template inline ResultType accum_dist(const U& a, const V& b, int) const { - return sqrt(static_cast(a)) - sqrt(static_cast(b)); + ResultType diff = sqrt(static_cast(a)) - sqrt(static_cast(b)); + return diff * diff; } }; @@ -729,9 +730,11 @@ struct KL_Divergence inline ResultType accum_dist(const U& a, const V& b, int) const { ResultType result = ResultType(); - ResultType ratio = (ResultType)(a / b); - if (ratio>0) { - result = a * log(ratio); + if( *b != 0 ) { + ResultType ratio = (ResultType)(a / b); + if (ratio>0) { + result = a * log(ratio); + } } return result; }