1 | initial version |
in the end, if you need to keep your double data, you cannot use compareHist(), have to forsake all opencv optimization, and roll your own:
double BHATTACHARYYA(const Mat &h1, const Mat &h2) {
CV_Assert(h1.type() == h2.type() == CV_64F);
double result = 0;
double s1=0, s2=0;
for (int j=0; j<h1.rows; j++) {
double a = h1.at<double>(j);
double b = h2.at<double>(j);
result += std::sqrt(a*b);
s1 += a;
s2 += b;
}
s1 *= s2;
s1 = fabs(s1) > FLT_EPSILON ? 1./std::sqrt(s1) : 1.;
result = std::sqrt(std::max(1. - result*s1, 0.));
return result;
}