• 灰色直方图图像匹配


    #include "opencv2/highgui/highgui.hpp"  
    #include "opencv/cv.hpp"  
    #include "string.h"
    
    
    //画直方图用  
    int HistogramBins = 256;
    float HistogramRange1[2] = { 0, 255 };
    float *HistogramRange[1] = { &HistogramRange1[0] };
    
    /*
    * imagefile1:
    * imagefile2:
    * method: could be CV_COMP_CHISQR, CV_COMP_BHATTACHARYYA, CV_COMP_CORREL, CV_COMP_INTERSECT
    */
    int CompareHist(const char* imagefile1, const char* imagefile2)
    {
        IplImage *image1 = cvLoadImage(imagefile1, 0);
        IplImage *image2 = cvLoadImage(imagefile2, 0);
    
        CvHistogram *Histogram1 = cvCreateHist(1, &HistogramBins, CV_HIST_ARRAY, HistogramRange);
        CvHistogram *Histogram2 = cvCreateHist(1, &HistogramBins, CV_HIST_ARRAY, HistogramRange);
    
        cvCalcHist(&image1, Histogram1);
        cvCalcHist(&image2, Histogram2);
    
        cvNormalizeHist(Histogram1, 1);
        cvNormalizeHist(Histogram2, 1);
    
        // CV_COMP_CHISQR,CV_COMP_BHATTACHARYYA这两种都可以用来做直方图的比较,值越小,说明图形越相似  
        printf("CV_COMP_CHISQR : %.4f
    ", cvCompareHist(Histogram1, Histogram2, CV_COMP_CHISQR));
        printf("CV_COMP_BHATTACHARYYA : %.4f
    ", cvCompareHist(Histogram1, Histogram2, CV_COMP_BHATTACHARYYA));
    
    
        // CV_COMP_CORREL, CV_COMP_INTERSECT这两种直方图的比较,值越大,说明图形越相似  
        printf("CV_COMP_CORREL : %.4f
    ", cvCompareHist(Histogram1, Histogram2, CV_COMP_CORREL));
        printf("CV_COMP_INTERSECT : %.4f
    ", cvCompareHist(Histogram1, Histogram2, CV_COMP_INTERSECT));
    
        cvReleaseImage(&image1);
        cvReleaseImage(&image2);
        cvReleaseHist(&Histogram1);
        cvReleaseHist(&Histogram2);
        return 0;
    }
    
    int main(int argc, char* argv[])
    {
        char path1[111];
        char path2[111];
        strcpy(path1, "C:\C_C++ code\Photo and video\mulpsq\psq0032.jpg");
        strcpy(path2, "C:\C_C++ code\Photo and video\mulpsq\psq0035.jpg");
        CompareHist(path1,path2);
        //CompareHist("d:\camera.jpg", "d:\camera1.jpg");  
        return 0;
    }
  • 相关阅读:
    将内容重定向到剪切板(clip.exe)
    加速数组操作(Array)
    错误信息输出,重定向到文件
    格式化数字字符串
    PowerShell常用的.Net 、COM对象(New-Object、Assembly)、加载程序集
    计算文件夹大小、拷贝文件显示进度
    草稿-Hyper-V
    右下角显示提示窗口(New-Object,COM)
    《TCP/IP详解卷一:协议》数据链路层(一)
    tcpdump抓包命令
  • 原文地址:https://www.cnblogs.com/mypsq/p/5001524.html
Copyright © 2020-2023  润新知