#include <stdio.h>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
Mat SrcImg, tempImg,DstImg;
/************************************************************************
* 用图像金字塔函数放大缩小图像
************************************************************************/
int main(int argc, char** argv)
{
cout<<"\n zoom in-out demo \n"<<endl;
cout<<"-----------------------------"<<endl;
cout<<"*[u]->zoom in \n"<<endl;
cout<<"*[d]->zoom out \n"<<endl;
cout<<"[Esc]->close progrom \n\n"<<endl;
// 读取图像,并判断读取是否成功
const char* filename = "lena.jpg";
SrcImg = imread(filename);
if (!SrcImg.data)
{
printf("No data! -- Exiting the program \n");
return -1;
}
tempImg = SrcImg;
DstImg = tempImg;
while (true)
{
int c;
c = waitKey(10);
// 按下Esc键,推出程序
if (27 == (char)c)
{
break;
}
// 按下u键,向上采样,放大图像
if ('u' == (char)c)
{
pyrUp(tempImg, DstImg, Size(tempImg.cols*2, tempImg.rows*2));
printf("** zoom in :image x 2 \n");
}
// 按下d键,向下采样,缩小图像
if ('d' == (char)c)
{
pyrDown(tempImg, DstImg, Size(tempImg.cols/2, tempImg.rows/2));
printf("** zoom out: image / 2 \n");
}
imshow("prys images", DstImg);
tempImg = DstImg;
}
return 0;
}
图像金字塔 pyrUp pyrDown
最新推荐文章于 2023-03-06 17:27:13 发布