int main()
{
Mat srcImage = imread("/1.jpg");
Mat tmpIamge, dstImage1, dstImage2;
tmpIamge = srcImage;
imshow("og", srcImage);
resize(tmpIamge, dstImage1, Size(tmpIamge.cols/2, tmpIamge.rows/2 ), (0, 0), (0, 0), 3);
resize(tmpIamge, dstImage2, Size(tmpIamge.cols*2, tmpIamge.rows*2 ), (0, 0), (0, 0), 3);
imshow("new1", dstImage1);
imshow("new2", dstImage2);
waitKey(0);
return 0;
第一个参数是输入图片;
第二个参数是输出图片;
第三个参数是输出图片的尺寸,Szie的类型是dsize;
第四个参数是double类型的fx,沿水平轴缩放系数;
第五个参数是double类型的fy,沿垂直轴缩放系数;
第六个参数是指定插值方式;
Mat srcImage = imread("1.jpg");
Mat tmpIamge, dstImage;
tmpIamge = srcImage;
imshow("og", srcImage);
pyrUp(tmpIamge, dstImage, Size(tmpIamge.cols*2, tmpIamge.rows*2 ));
imshow("new", dstImage);
waitKey(0);
return 0;
第一个参数是输入图片;
第二个参数是输出图片;
第三个参数是输出图片的尺寸,Szie的类型是dsize;
【注】默认是输入图片的行列*2大小来计算
Mat srcImage = imread("1.jpg");
Mat tmpIamge, dstImage;
tmpIamge = srcImage;
imshow("og", srcImage);
pyrDown(tmpIamge, dstImage, Size(tmpIamge.cols/2, tmpIamge.rows/2 ));
imshow("new", dstImage);
waitKey(0);
return 0;
#define WINDOW_NAME "lexus"
Mat g_srcImage, g_dstIamge, g_tmpIamge;
int main(int, char**)
{
string path = "lexus.jpg";
g_srcImage = imread(path);
if (!g_srcImage.data) {
printf("GG simida!\n");
return 0;
}
namedWindow(WINDOW_NAME, WINDOW_AUTOSIZE);
imshow(WINDOW_NAME, g_srcImage);
g_tmpIamge = g_srcImage;
g_dstIamge = g_tmpIamge;
int key = 0;
while (1)
{
key = waitKey(9); // 读取键值到key中
switch (key)
{
// 退出操作
case 27:
return 0;
break;
case 'q':
return 0;
break;
// 放大操作
case 'a':
pyrUp(g_tmpIamge, g_dstIamge, Size(g_tmpIamge.cols*2,g_tmpIamge.rows*2));
printf("检测到按键'a',基于pyrUp,放大一倍\n");
break;
case 'w':
resize(g_tmpIamge, g_dstIamge, Size(g_tmpIamge.cols*2,g_tmpIamge.rows*2));
printf("检测到按键'w',基于resize,放大一倍\n");
break;
case '1':
resize(g_tmpIamge, g_dstIamge, Size(g_tmpIamge.cols*2,g_tmpIamge.rows*2));
printf("检测到按键'1',基于resize,放大一倍\n");
break;
case '3':
pyrUp(g_tmpIamge, g_dstIamge, Size(g_tmpIamge.cols*2,g_tmpIamge.rows*2));
printf("检测到按键'3',基于pyrUp,放大一倍\n");
break;
// 缩小
case 'd':
pyrDown(g_tmpIamge, g_dstIamge, Size(g_tmpIamge.cols/2,g_tmpIamge.rows/2));
printf("检测到按键'd',基于pyrDown,缩小一倍\n");
break;
case 's':
resize(g_tmpIamge, g_dstIamge, Size(g_tmpIamge.cols/2,g_tmpIamge.rows/2));
printf("检测到按键's',基于resize,缩小一倍\n");
break;
case '2':
resize(g_tmpIamge, g_dstIamge, Size(g_tmpIamge.cols/2,g_tmpIamge.rows/2));
printf("检测到按键'2',基于resize,缩小一倍\n");
break;
case '4':
resize(g_tmpIamge, g_dstIamge, Size(g_tmpIamge.cols/2,g_tmpIamge.rows/2));
printf("检测到按键'4',基于pyrDown,缩小一倍\n");
break;
}
imshow(WINDOW_NAME, g_dstIamge);
g_tmpIamge = g_dstIamge;
}
return 0;
}