|
#include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> using namespace std; using namespace cv; int main( int, char** argv ) { Mat src1,src2,gray1,gray2; src1 = imread(argv[1]); src2 = imread(argv[2]); cvtColor(src1, gray1, CV_BGR2GRAY); cvtColor(src2, gray2, CV_BGR2GRAY); int histSize = 256; float range[] = { 0, 256 } ; const float* histRange = { range }; int channels[] = {0}; Mat hist1,hist2; calcHist( &gray1, 1, channels, Mat(), hist1, 1, &histSize, &histRange); calcHist( &gray2, 1, channels, Mat(), hist2, 1, &histSize, &histRange); //相关:CV_COMP_CORREL //卡方:CV_COMP_CHISQR //直方图相交:CV_COMP_INTERSECT //Bhattacharyya距离:CV_COMP_BHATTACHARYYA double diff = compareHist(hist1,hist2,CV_COMP_BHATTACHARYYA); cout << diff << endl; }
OpenCV2马拉松第12圈——直方图比较,布布扣,bubuko.com
原文:http://blog.csdn.net/abcd1992719g/article/details/25511627