#include <opencv2/opencv.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
#define WINDOW_NAME "【程序窗口】"
Mat g_srcImage, g_dstImage, g_tmpImage;
//static void ShowHelpText();
/*int main()
{
Mat srcImage = imread("1.jpg");
Mat tmpImage, dstImage1, dstImage2;
tmpImage = srcImage;
imshow("initial picture", srcImage);
resize(tmpImage, dstImage1, Size(tmpImage.cols / 2, tmpImage.rows / 2), (0, 0), (0, 0), 3);
resize(tmpImage, dstImage2, Size(tmpImage.cols * 2, tmpImage.rows * 2), (0, 0), (0, 0), 3);
imshow("suoxiao", dstImage1);
imshow("fangda", dstImage2);
waitKey(0);
return 0;
}*/
//向下采样
/*int main()
{
Mat srcImage = imread("1.jpg");
Mat tmpImage, dstImage;
tmpImage = srcImage;
imshow("initial picture", srcImage);
pyrDown(tmpImage, dstImage, Size(tmpImage.cols / 2, tmpImage.rows / 2));//向下
pyrUp(tmpImage, dstImage, Size(tmpImage.cols / 2, tmpImage.rows / 2));//向上
imshow("xiangxiacaiyang", dstImage);
waitKey(0);
return 0;
}*/
static void ShowHelpText()
{
printf("\n\t图像金字塔和resize实例程序\n\t");
printf("\t\t按键a基于pyrUp放大\n"
"\t\t按键b基于pyrDown缩小\n"
"\t\t按键c基于resize放大\n"
"\t\t按键d基于resize缩小\n"
);
}
int main()
{
system("color 2F");
ShowHelpText();
g_srcImage = imread("1.jpg");
if (!g_srcImage.data)
{
printf("Oh,imread error \n");
return false;
}
namedWindow(WINDOW_NAME, WINDOW_AUTOSIZE);
imshow(WINDOW_NAME, g_srcImage);
g_tmpImage = g_srcImage;
g_dstImage = g_tmpImage;
int key = 0;
while (1)
{
key = waitKey(9);
switch (key)
{
case 27:
return 0;
break;
case 'q':
return 0;
break;
case'a':
pyrUp(g_tmpImage, g_dstImage, Size(g_tmpImage.cols * 2, g_tmpImage.rows * 2));//向上
printf("a,放大\n");
break;
case'b':
pyrDown(g_tmpImage, g_dstImage, Size(g_tmpImage.cols / 2, g_tmpImage.rows / 2));//向上
printf("b,缩小\n");
break;
case'c':
resize(g_tmpImage, g_dstImage, Size(g_tmpImage.cols * 2, g_tmpImage.rows * 2), (0, 0), (0, 0), 3);
printf("c,放大\n");
break;
case'd':
resize(g_tmpImage, g_dstImage, Size(g_tmpImage.cols / 2, g_tmpImage.rows / 2), (0, 0), (0, 0), 3);
printf("d,缩小\n");
break;
}
imshow("xiangxiacaiyang",g_dstImage);
g_tmpImage = g_dstImage;
}
}