码迷,mamicode.com
首页 > 其他好文 > 详细

opencv:图像直方图相似性比较

时间:2020-01-31 22:23:24      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:histsize   range   ali   http   src   oid   als   lse   compare   

技术图片

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\th11 = %.2f\n", h12_bhattacharyya, h11_bhattacharyya);
    printf("相关性: h12 = %.2f\th11 = %.2f\n", h12_correl, h11_correl);
}

opencv:图像直方图相似性比较

标签:histsize   range   ali   http   src   oid   als   lse   compare   

原文地址:https://www.cnblogs.com/wbyixx/p/12246926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!