opencv/samples/cpp/tutorial_code/ImgProc/Pyramids.cpp

78 lines
1.5 KiB
C++
Raw Normal View History

/**
* @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"
using namespace cv;
/// Global variables
Mat src, dst, tmp;
const char* window_name = "Pyramids Demo";
/**
* @function main
*/
int main( void )
{
/// 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
if( src.empty() )
{ printf(" No data! -- Exiting the program \n");
return -1; }
2016-07-18 21:32:05 +08:00
//![load]
2012-10-17 07:18:30 +08:00
tmp = src;
dst = tmp;
2016-07-18 21:32:05 +08:00
//![create_window]
imshow( window_name, dst );
2016-07-18 21:32:05 +08:00
//![create_window]
2016-07-18 21:32:05 +08:00
//![infinite_loop]
for(;;)
2012-10-17 07:18:30 +08:00
{
int c;
2016-07-18 21:32:05 +08:00
c = waitKey(0);
if( (char)c == 27 )
{ break; }
if( (char)c == 'u' )
2016-07-18 21:32:05 +08:00
{
//![pyrup]
pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) );
//![pyrup]
2012-10-17 07:18:30 +08:00
printf( "** Zoom In: Image x 2 \n" );
}
else if( (char)c == 'd' )
2016-07-18 21:32:05 +08:00
{
//![pyrdown]
pyrDown( tmp, dst, Size( tmp.cols/2, tmp.rows/2 ) );
//![pyrdown]
printf( "** Zoom Out: Image / 2 \n" );
}
imshow( window_name, dst );
2016-07-18 21:32:05 +08:00
//![update_tmp]
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
return 0;
}