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