实验环境:VS2010 + OpenCV2.4.9.0
#include <iostream>
#include "cv.h"
#include <highgui.h>
using namespace std;
using namespace cv;
int main(int argc,char*argv[])
{
char* wndName = "Pyramids Demo";
Mat img = imread("lena.jpg");
if(!img.data)
{
cerr <<"No Data!" << endl;
exit(1);
}
Mat tmp = img.clone();
Mat dst = tmp;
namedWindow(wndName,CV_WINDOW_AUTOSIZE);
imshow(wndName,dst);
while(TRUE)
{
char c;
c = waitKey(10);
if(c == 27)
{
break;
}
if(c == 'u')
{
pyrUp(tmp,dst,Size(tmp.cols * 2,tmp.rows * 2));
cout << "Zoom In: x2" <<endl;
}
else if(c == 'd')
{
pyrDown(tmp,dst,Size(tmp.cols/2,tmp.rows/2));
cout << "Zoom Out: /2" << endl;
}
imshow(wndName,dst);
tmp = dst;
}
return 1;
}
实验结果:
原图:
两倍:(实际不是两倍,图片太大不能上传)
小两倍:
参考文献:
http://docs.opencv.org/doc/tutorials/imgproc/pyramids/pyramids.html
链接一篇使用旧版本的例子:
http://blog.youkuaiyun.com/hitwengqi/article/details/6857441