zoukankan      html  css  js  c++  java
  • 直方图比较

    通过比较两幅图像的灰度直方图来确定相似性

    一共四种方法

    第一种:相关性比较

     值的范围是-1~1相关性由小到大

    第二种:卡方计算

     越小表示相关性越强

    第三种:十字交叉运算

    第四种:巴氏距离计算

    取值范围0~1,距离越小相关性越强

    运算之前先要把rgb转化为hsv,然后将像素值归一化到0~1之间

    #include<iostream>
    #include<opencv2/opencv.hpp>
    
    using namespace std;
    using namespace cv;
    
    int main(int argc, char**argv)
    {
        Mat  base,test1,test2;
        base=imread("C:/Users/hs769/Desktop/1.jpg");
        test1 = imread("C:/Users/hs769/Desktop/2.jpg");
        imshow("demo", base);
    
        //cvtColor(base, test1, COLOR_RGB2GRAY);
        cvtColor(test1, test1, COLOR_RGB2HSV);
        cvtColor(base, test2, COLOR_RGB2HSV);
    
        int h_bin = 50;
        int s_bin = 60;
        int histSize[] = { h_bin,s_bin };
        float h_range[] = { 0,180 };
        float s_range[] = { 0,256 };
    
        const float *range[] = { h_range,s_range };
    
        int channels[] = { 0,1 };
        MatND hist_test1;
        MatND hist_test2;
    
    
        calcHist(&test1, 1, channels, Mat(), hist_test1, 2, histSize, range, true, false);
        normalize(hist_test1, hist_test1, 0, 1, NORM_MINMAX, -1, Mat());
    
        calcHist(&test2, 1, channels, Mat(), hist_test2, 2, histSize, range, true, false);
        normalize(hist_test2, hist_test2, 0, 1, NORM_MINMAX, -1, Mat());
    
        double test1test2 = compareHist(hist_test1, hist_test2, HISTCMP_CORREL);
        cout << "method1 value" << test1test2 << endl;
    
        waitKey(0);
        return 0;
    }

  • 相关阅读:
    装饰器
    函数对象与闭包
    名称空间与作用域
    函数的参数
    函数的基本使用
    ${}与#{}的区别
    thymeleaf之日期格式化
    template might not exist or might not be accessible by any of the configured Template Resolvers
    springboot使用@Scheduled之cron表达式详解
    自定义springboot项目启动图案
  • 原文地址:https://www.cnblogs.com/wangtianning1223/p/13303081.html
Copyright © 2011-2022 走看看