利用按键,简单的进行缩放图片

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<opencv2/opencv.hpp>
#define window1 "【结果1】"
#define window  "【原图 】"
#define window2 "【结果2】"
#define window3 "【结果3】"
#define window4 "【结果4】"
#define window5 "【结果5】"

using namespace std;
using namespace cv;


Mat dst;


//用按键来进行放大缩小图片,功能:ws用resize函数来进行放大和缩小图片,ad用pyrdown和pyrup来进行放大和缩小,r:恢复原来的图像。
int main()
{
	//1.读取原图。
	Mat src;
	src = imread("女神.jpg",1);
	//resize(src,src,Size(),0.4,0.4);
	//2.准备临时图像和输出图像。
	
	Mat tmp;
	src.copyTo(dst);
	src.copyTo(tmp);
	//2.5 输出提示信息。
	cout << "               HELP             " << endl;
	cout << "    w:  use resize  enlarge map." << endl;
	cout << "    s:  use resize  shrink  map." << endl;
	cout << "    a:  use pyrdown enlarge map." << endl;
	cout << "    d:  use pyrup   shrink  map." << endl;
	//3.用while()函数来进行循环处理。
	
	while (1)
	{
		int c;
		c=waitKey(1);
		
		switch (c)
		{
		case 'q'://quit
			return 0;
			break;
		case 27://esc
			return 0;
			break;
		case 'r'://恢复原图大小。
			cout << "set origenimage!!" << endl;
			src.copyTo(dst);
			break;
		case 'w':
			cout << "use resize enlarge!" << endl;
			resize(tmp,dst, Size(2 *tmp.rows, 2 * tmp.cols));
			break;
		case 's':
			cout << "use resize shrink!!"<<endl;
			resize(tmp, dst, Size(tmp.rows / 2, tmp.cols / 2));
			break;
		case 'a':
			cout << "use pyrdown enlarge!"<<endl;
			pyrDown(tmp, dst);
			break;
		case 'd':
			cout << "use pyrup shrink!"<<endl;
			pyrUp(tmp, dst);
			break;
		};
		tmp = dst;
	
		namedWindow(window1,WINDOW_AUTOSIZE);
		imshow(window1,dst);


	}
	



	return 0;


}


在这里插入图片描述在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值