EqualizeHist_Demo.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @function EqualizeHist_Demo.cpp
  3. * @brief Demo code for equalizeHist function
  4. * @author OpenCV team
  5. */
  6. #include "opencv2/imgcodecs.hpp"
  7. #include "opencv2/highgui.hpp"
  8. #include "opencv2/imgproc.hpp"
  9. #include <iostream>
  10. using namespace cv;
  11. using namespace std;
  12. /**
  13. * @function main
  14. */
  15. int main( int argc, char** argv )
  16. {
  17. //! [Load image]
  18. CommandLineParser parser( argc, argv, "{@input | lena.jpg | input image}" );
  19. Mat src = imread( samples::findFile( parser.get<String>( "@input" ) ), IMREAD_COLOR );
  20. if( src.empty() )
  21. {
  22. cout << "Could not open or find the image!\n" << endl;
  23. cout << "Usage: " << argv[0] << " <Input image>" << endl;
  24. return -1;
  25. }
  26. //! [Load image]
  27. //! [Convert to grayscale]
  28. cvtColor( src, src, COLOR_BGR2GRAY );
  29. //! [Convert to grayscale]
  30. //! [Apply Histogram Equalization]
  31. Mat dst;
  32. equalizeHist( src, dst );
  33. //! [Apply Histogram Equalization]
  34. //! [Display results]
  35. imshow( "Source image", src );
  36. imshow( "Equalized Image", dst );
  37. //! [Display results]
  38. //! [Wait until user exits the program]
  39. waitKey();
  40. //! [Wait until user exits the program]
  41. return 0;
  42. }