1.这个程序就是图像金字塔的最基本操作(缩放图像)
#include <opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\core\core.hpp>

using namespace cv;
using namespace std;

int main()
{
Mat srcImg=imread(“1.jpg”);
//Mat dstImg=Mat::zeros(80,800,CV_8UC3); //对于size类型的东西里面代表x,y也就是宽和高的计算,制造行列
// resize(srcImg,dstImg,dstImg.size()); //行列的缩放系数会根据dstImg的大小会自动计算出来
//imshow(“缩放的图片”,dstImg);
//imshow(“原图像的图片”,srcImg);
//Mat dstImg;
// resize(srcImg,dstImg,Size(),0.5,0.5);//缩小图片的尺寸
//imshow(“原图”,srcImg);
//imshow(“缩放图片”,dstImg);
Mat dstImg,dstImg1;
resize(srcImg,dstImg,Size(srcImg.cols,srcImg.rows*2),(0,0),(0,0),3); //按照程序定义的来吧
resize(srcImg,dstImg1,Size(srcImg.cols/2,srcImg.rows/2),(0,0),(0,0),3);
imshow(“放”,dstImg);
imshow(“缩”,dstImg1);
waitKey(0);
return 0;
}

2.图像金字塔向上向下采样
#include <opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat srcImg=imread(“1.jpg”);
//pryUp函数的作用是向上采样并模糊一张图像说白了就是放大一张图片,先插入可为0的行和列,对原图像进行向上取样操作然后将结果与PRYdown乘以4的内核做卷积
Mat tmpImg,dstImg,dstImg1;
tmpImg=srcImg;
imshow(“原图像”,srcImg);

pyrUp(tmpImg,dstImg,Size(srcImg.cols2,srcImg.rows2));
// pyrUp(tmpImg,dstImg1,Size(srcImg.cols1.2,srcImg.rows1.2));
pyrDown(tmpImg,dstImg1,Size(srcImg.cols/2,srcImg.rows/2));
imshow(“面积放大4倍的图像”,dstImg);
imshow(“面积缩小4倍的图像”,dstImg1);
//无论是缩小还是放大图像,结果图像都会变得不清楚地
waitKey(0);
return 0;
}

3.图像金字塔配合键盘交互的操作:
#include <opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>

using namespace cv;
using namespace std;

#define WINDOW_NAME “程序窗口”

Mat srcImg,dstImg,tmpImg;

int main()
{
srcImg=imread(“1.jpg”);
if(!srcImg.data)
{
printf(“读取图片出错”);
return 0;
}
namedWindow(WINDOW_NAME,WINDOW_AUTOSIZE);
imshow(WINDOW_NAME,srcImg);
tmpImg=srcImg;
dstImg=tmpImg;
int key=0;
while(1)
{
key=waitKey(9);
switch(key){
case 27:return 0;break;
case ‘q’:return 0;break;
case ‘a’: cout <<“按键a背按下,执行pryup函数进行图片放大”<<endl;
pyrUp(tmpImg,dstImg,Size(srcImg.cols2,srcImg.rows2));
break;
case ‘w’: cout <<“按键w被按下,执行resize函数进行图片放大操作”<<endl;
resize(tmpImg,dstImg,Size(srcImg.cols2,srcImg.rows2));
break;
case ‘1’:cout<<“按键1被按下来,调用resize函数进行放大操作”<<endl;
resize(tmpImg,dstImg,Size(srcImg.cols2,srcImg.rows2));
break;
case ‘3’:cout <<“按键3被按下来,调用pyrUp操作进行图片放大”<<endl;
pyrUp(tmpImg,dstImg,Size(srcImg.cols2,srcImg.rows2));
break;
case ‘d’:cout<<“按键d被按下来,调用pyrDown函数进行图片放大操作”<<endl;
pyrDown(tmpImg,dstImg,Size(tmpImg.cols/2,tmpImg.rows/2));
break;
case ‘s’:cout <<“按键s被按下来,调用resize函数进行图片缩小运算”<<endl;
resize(tmpImg,dstImg,Size(tmpImg.cols/2,tmpImg.rows/2));
break;
case ‘2’:cout <<“按键2被按下,调用resize函数进行图片缩小运算”<<endl;
resize(tmpImg,dstImg,Size(tmpImg.cols/2,tmpImg.rows/2));
break;
case ‘4’:cout <<“按键4被按下,调用pyrDown函数进行图片缩小运算”<<endl;
pyrDown(tmpImg,dstImg,Size(tmpImg.cols/2,tmpImg.rows/2));
break;
}
imshow(WINDOW_NAME,dstImg);
tmpImg=dstImg;
}
return 0;//在进行图像放大和缩小的时候一定要注意限制,对大小均会有所限制的
}