Pyramids.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @file Pyramids.cpp
  3. * @brief Sample code of image pyramids (pyrDown and pyrUp)
  4. * @author OpenCV team
  5. */
  6. #include "iostream"
  7. #include "opencv2/imgproc.hpp"
  8. #include "opencv2/imgcodecs.hpp"
  9. #include "opencv2/highgui.hpp"
  10. using namespace std;
  11. using namespace cv;
  12. const char* window_name = "Pyramids Demo";
  13. /**
  14. * @function main
  15. */
  16. int main( int argc, char** argv )
  17. {
  18. /// General instructions
  19. cout << "\n Zoom In-Out demo \n "
  20. "------------------ \n"
  21. " * [i] -> Zoom in \n"
  22. " * [o] -> Zoom out \n"
  23. " * [ESC] -> Close program \n" << endl;
  24. //![load]
  25. const char* filename = argc >=2 ? argv[1] : "chicky_512.png";
  26. // Loads an image
  27. Mat src = imread( samples::findFile( filename ) );
  28. // Check if image is loaded fine
  29. if(src.empty()){
  30. printf(" Error opening image\n");
  31. printf(" Program Arguments: [image_name -- default chicky_512.png] \n");
  32. return EXIT_FAILURE;
  33. }
  34. //![load]
  35. //![loop]
  36. for(;;)
  37. {
  38. //![show_image]
  39. imshow( window_name, src );
  40. //![show_image]
  41. char c = (char)waitKey(0);
  42. if( c == 27 )
  43. { break; }
  44. //![pyrup]
  45. else if( c == 'i' )
  46. { pyrUp( src, src, Size( src.cols*2, src.rows*2 ) );
  47. printf( "** Zoom In: Image x 2 \n" );
  48. }
  49. //![pyrup]
  50. //![pyrdown]
  51. else if( c == 'o' )
  52. { pyrDown( src, src, Size( src.cols/2, src.rows/2 ) );
  53. printf( "** Zoom Out: Image / 2 \n" );
  54. }
  55. //![pyrdown]
  56. }
  57. //![loop]
  58. return EXIT_SUCCESS;
  59. }