1 /**
2 * @file Pyramids.cpp
3 * @brief Sample code of image pyramids (pyrDown and pyrUp)
4 * @author OpenCV team
5 */
6
7 #include "opencv2/imgproc/imgproc.hpp"
8 #include "opencv2/imgcodecs.hpp"
9 #include "opencv2/highgui/highgui.hpp"
10 #include <math.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13
14 using namespace cv;
15
16 /// Global variables
17 Mat src, dst, tmp;
18
19 const char* window_name = "Pyramids Demo";
20
21
22 /**
23 * @function main
24 */
main(void)25 int main( void )
26 {
27 /// General instructions
28 printf( "\n Zoom In-Out demo \n " );
29 printf( "------------------ \n" );
30 printf( " * [u] -> Zoom in \n" );
31 printf( " * [d] -> Zoom out \n" );
32 printf( " * [ESC] -> Close program \n \n" );
33
34 /// Test image - Make sure it s divisible by 2^{n}
35 src = imread( "../data/chicky_512.png" );
36 if( src.empty() )
37 { printf(" No data! -- Exiting the program \n");
38 return -1; }
39
40 tmp = src;
41 dst = tmp;
42
43 /// Create window
44 namedWindow( window_name, WINDOW_AUTOSIZE );
45 imshow( window_name, dst );
46
47 /// Loop
48 for(;;)
49 {
50 int c;
51 c = waitKey(10);
52
53 if( (char)c == 27 )
54 { break; }
55 if( (char)c == 'u' )
56 { pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) );
57 printf( "** Zoom In: Image x 2 \n" );
58 }
59 else if( (char)c == 'd' )
60 { pyrDown( tmp, dst, Size( tmp.cols/2, tmp.rows/2 ) );
61 printf( "** Zoom Out: Image / 2 \n" );
62 }
63
64 imshow( window_name, dst );
65 tmp = dst;
66 }
67
68 return 0;
69 }
70