算法看起来比较复杂,但是由于opencv已经有内置实现代码,因此调用代码比较简单:
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
Mat srcImage = imread("F:\\opencv_re_learn\\2.jpg");
if (!srcImage.data){
cout << "failed to read" << endl;
system("pause");
return -1;
}
imshow("srcImage", srcImage);
Mat srcGray;
//conver to gray
cvtColor(srcImage, srcGray, CV_BGR2GRAY);
Mat heqResult;
equalizeHist(srcGray, heqResult);
imshow("heqResult", heqResult);
waitKey(0);
return 0;
}
实现效果: