此方法使用直方图模型比对两张图片,如果两张图片一模一样的话,结果为0.00;比对的结果越小,图片相似性越高;
适用于比较两张尺寸大小一致的图片,对于大小不一致的图片,只能比较其相似性;
-(double)CompareHist:(IplImage*)image1 withParam2:(IplImage*)image2 { int hist_size = 256; float range[] = {0,255}; IplImage *gray_plane = cvCreateImage(cvGetSize(image1), 8, 1); cvCvtColor(image1, gray_plane, CV_BGR2GRAY); CvHistogram *gray_hist = cvCreateHist(1, &hist_size, CV_HIST_ARRAY); cvCalcHist(&gray_plane, gray_hist); IplImage *gray_plane2 = cvCreateImage(cvGetSize(image2), 8, 1); cvCvtColor(image2, gray_plane2, CV_BGR2GRAY); CvHistogram *gray_hist2 = cvCreateHist(1, &hist_size, CV_HIST_ARRAY); cvCalcHist(&gray_plane2, gray_hist2); return cvCompareHist(gray_hist, gray_hist2, CV_COMP_BHATTACHARYYA); }
ios--OpenCV--cvCompareHist使用直方图模型(CvHistogram)比对两张图片,布布扣,bubuko.com