opencv:图像直方图相似性比较
Posted wbyixx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv:图像直方图相似性比较相关的知识,希望对你有一定的参考价值。
void hist_compare(Mat src1, Mat src2) {
int histSize[] = { 256, 256, 256 };
int channels[] = { 0, 1, 2 };
Mat hist1, hist2;
float c1[] = { 0, 255 };
float c2[] = { 0, 255 };
float c3[] = { 0, 255 };
const float* histRanges[] = { c1, c2, c3 };
calcHist(&src1, 1, channels, Mat(), hist1, 3, histSize, histRanges, true, false);
calcHist(&src2, 1, channels, Mat(), hist2, 3, histSize, histRanges, true, false);
// 归一化
normalize(hist1, hist1, 0, 1.0, NORM_MINMAX, -1, Mat());
normalize(hist2, hist2, 0, 1.0, NORM_MINMAX, -1, Mat());
// 比较 - 巴氏距离
double h12_bhattacharyya = compareHist(hist1, hist2, HISTCMP_BHATTACHARYYA);
double h11_bhattacharyya = compareHist(hist1, hist1, HISTCMP_BHATTACHARYYA);
// 比较 - 相关性比较
double h12_correl = compareHist(hist1, hist2, HISTCMP_CORREL);
double h11_correl = compareHist(hist1, hist1, HISTCMP_CORREL);
printf("巴氏距离: h12 = %.2f h11 = %.2f
", h12_bhattacharyya, h11_bhattacharyya);
printf("相关性: h12 = %.2f h11 = %.2f
", h12_correl, h11_correl);
}
以上是关于opencv:图像直方图相似性比较的主要内容,如果未能解决你的问题,请参考以下文章