<strong>#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
Mat src, dst, tmp;
char* window_name = "Pyrdmids Demo";
int main()
{
system("color 2E");
src = imread("奥巴马.jpg");
if (!src.data)
{
cerr << "Can not open this image!" << endl;
return EXIT_FAILURE;
}
tmp = src;
dst = tmp;
namedWindow(window_name);
imshow("Initial Image", src);
while (true)
{
int c;
c = waitKey(10);
if ((char)c == 27)
{
break;
}
if ((char)c == 'u')
{
pyrUp(tmp, dst, Size(tmp.cols * 2, tmp.rows * 2));
cout << "\n***Image × 2***" << endl;
}
else if ((char)c == 'd')
{
pyrDown(tmp, dst, Size(tmp.cols / 2, tmp.rows / 2));
cout << "\n***Image ÷ 2***" << endl;
}
imshow(window_name, dst);
tmp = dst;
}
system("pause");
return 0;
}</strong>