1 #include "opencv2/highgui/highgui.hpp" 2 #include "opencv2/imgproc/imgproc.hpp" 3 #include <iostream> 4 #include <stdio.h> 5 6 using namespace cv; 7 using namespace std; 8 9 /** @function main */ 10 int main( int argc, char** argv ) 11 { 12 Mat src, dst; 13 14 char* source_window = "Source image"; 15 char* equalized_window = "Equalized Image"; 16 17 /// 加载源图像 18 src = imread( argv[1], 1 ); 19 20 if( !src.data ) 21 { cout<<"Usage: ./Histogram_Demo <path_to_image>"<<endl; 22 return -1;} 23 24 /// 转为灰度图 25 cvtColor( src, src, CV_BGR2GRAY ); 26 27 /// 应用直方图均衡化 28 equalizeHist( src, dst ); 29 30 /// 显示结果 31 namedWindow( source_window, CV_WINDOW_AUTOSIZE ); 32 namedWindow( equalized_window, CV_WINDOW_AUTOSIZE ); 33 34 imshow( source_window, src ); 35 imshow( equalized_window, dst ); 36 37 /// 等待用户按键退出程序 38 waitKey(0); 39 40 return 0; 41 }