别人的代码:
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
void drawHist(Mat &hist, int type, string name) //归一化并绘制直方图函数
{
int hist_w = 512;
int hist_h = 400;
int width = 2;
Mat histImage = Mat::zeros(hist_h, hist_w, CV_8UC3);
normalize(hist, hist, 1, 0, type, -1, Mat());
for (int i = 1; i <= hist.rows; i++)
{
rectangle(histImage, Point(width*(i - 1), hist_h - 1),
Point(width*i - 1, hist_h - cvRound(20 * hist_h*hist.at<float>(i - 1)) - 1),
Scalar(255, 255, 255), -1);
}
imshow(name, histImage);
} //主函数
int main()
{
Mat img1 = imread("F://download//第三章图片//Fig0354(a)(einstein_orig).tif");
Mat img2 = imread("F://download//第三章图片//Fig0314(a)(100-dollars).tif");
if (img1.empty() || img2.empty())
{
cout << "请确认图像文件名称是否正确" << endl;
return -1;
}
Mat hist1, hist2;
//计算两张图像直方图
cons