2011-06-22 04:33:35 +08:00
|
|
|
/**
|
|
|
|
* @file Pyramids.cpp
|
|
|
|
* @brief Sample code of image pyramids (pyrDown and pyrUp)
|
|
|
|
* @author OpenCV team
|
|
|
|
*/
|
|
|
|
|
2016-02-15 21:37:29 +08:00
|
|
|
#include "opencv2/imgproc.hpp"
|
2014-07-04 22:48:15 +08:00
|
|
|
#include "opencv2/imgcodecs.hpp"
|
2016-02-15 21:37:29 +08:00
|
|
|
#include "opencv2/highgui.hpp"
|
2011-06-22 04:33:35 +08:00
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
|
|
|
|
/// Global variables
|
|
|
|
Mat src, dst, tmp;
|
|
|
|
|
2012-11-07 22:21:20 +08:00
|
|
|
const char* window_name = "Pyramids Demo";
|
2011-06-22 04:33:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function main
|
|
|
|
*/
|
2012-11-07 22:21:20 +08:00
|
|
|
int main( void )
|
2011-06-22 04:33:35 +08:00
|
|
|
{
|
|
|
|
/// General instructions
|
|
|
|
printf( "\n Zoom In-Out demo \n " );
|
|
|
|
printf( "------------------ \n" );
|
|
|
|
printf( " * [u] -> Zoom in \n" );
|
|
|
|
printf( " * [d] -> Zoom out \n" );
|
|
|
|
printf( " * [ESC] -> Close program \n \n" );
|
|
|
|
|
2016-07-18 21:32:05 +08:00
|
|
|
//![load]
|
|
|
|
src = imread( "../data/chicky_512.png" ); // Loads the test image
|
2014-08-13 19:08:27 +08:00
|
|
|
if( src.empty() )
|
2011-06-22 04:33:35 +08:00
|
|
|
{ printf(" No data! -- Exiting the program \n");
|
|
|
|
return -1; }
|
2016-07-18 21:32:05 +08:00
|
|
|
//![load]
|
2011-06-22 04:33:35 +08:00
|
|
|
|
2012-10-17 07:18:30 +08:00
|
|
|
tmp = src;
|
2011-06-22 04:33:35 +08:00
|
|
|
dst = tmp;
|
|
|
|
|
2016-07-18 21:32:05 +08:00
|
|
|
//![create_window]
|
2011-06-22 04:33:35 +08:00
|
|
|
imshow( window_name, dst );
|
2016-07-18 21:32:05 +08:00
|
|
|
//![create_window]
|
2011-06-22 04:33:35 +08:00
|
|
|
|
2016-07-18 21:32:05 +08:00
|
|
|
//![infinite_loop]
|
2012-11-07 22:21:20 +08:00
|
|
|
for(;;)
|
2012-10-17 07:18:30 +08:00
|
|
|
{
|
2016-08-12 21:11:30 +08:00
|
|
|
char c = (char)waitKey(0);
|
2011-06-22 04:33:35 +08:00
|
|
|
|
2016-08-12 21:11:30 +08:00
|
|
|
if( c == 27 )
|
2011-06-22 04:33:35 +08:00
|
|
|
{ break; }
|
2016-08-12 21:11:30 +08:00
|
|
|
//![pyrup]
|
|
|
|
if( c == 'u' )
|
|
|
|
{ pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) );
|
2012-10-17 07:18:30 +08:00
|
|
|
printf( "** Zoom In: Image x 2 \n" );
|
2011-06-22 04:33:35 +08:00
|
|
|
}
|
2016-08-12 21:11:30 +08:00
|
|
|
//![pyrup]
|
|
|
|
//![pyrdown]
|
|
|
|
else if( c == 'd' )
|
|
|
|
{ pyrDown( tmp, dst, Size( tmp.cols/2, tmp.rows/2 ) );
|
2011-06-22 04:33:35 +08:00
|
|
|
printf( "** Zoom Out: Image / 2 \n" );
|
|
|
|
}
|
2016-08-12 21:11:30 +08:00
|
|
|
//![pyrdown]
|
2011-06-22 04:33:35 +08:00
|
|
|
imshow( window_name, dst );
|
2016-07-18 21:32:05 +08:00
|
|
|
|
|
|
|
//![update_tmp]
|
2011-06-22 04:33:35 +08:00
|
|
|
tmp = dst;
|
2016-07-18 21:32:05 +08:00
|
|
|
//![update_tmp]
|
2012-10-17 07:18:30 +08:00
|
|
|
}
|
2016-07-18 21:32:05 +08:00
|
|
|
//![infinite_loop]
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2011-06-22 04:33:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|