截取图片和压缩图片(Mat格式)

截取图片和压缩图片(Mat格式)

参考文献:
1.resize()的用法: https://blog.csdn.net/i_chaoren/article/details/54564663

2.截取图片:Rect area(550, 200, 680, 680); //Rect area [x, y, width, heigth];(x, y) 为裁剪区域的起始点坐标; (width, heigth) 为所裁剪区域的尺寸信息

#include <iostream>  
#include <opencv2/core/core.hpp>  
#include <opencv2/highgui/highgui.hpp>  
#include<opencv2/opencv.hpp>
#include<string>
//输出图片是是224x224像素的PNG格式
//对于IplImage * img 类型的图像,cvSaveImage(ImgName3, out)无法保存,本程序转为mat格式保存
using namespace cv;
using namespace std;
void PictureResize();
void PictureResize1();

int main() {
	//PictureResize();
	PictureResize1();
	return 0;
}

void PictureResize1() {
	for (int i = 1; i < 13; i++) {
		string ImgName, ImgName2;
		ImgName = "D:\\Master_project_TJH\\test_wzy\\ImageExample\\" + to_string(i) + ".bmp";
		Mat img = imread(ImgName);
		cout << "读取成功." << endl;

		//截取图片
		Rect area(550, 200, 680, 680);//Rect area [x, y, width, heigth];(x, y) 为裁剪区域的起始点坐标; (width, heigth) 为所裁剪区域的尺寸信息
		Mat img_region = img(area);

		//压缩图片
		Mat img_final;
		resize(img_region, img_final, Size(224, 224), 0, 0, INTER_LINEAR);

		ImgName2 = "D:\\Master_project_TJH\\test_wzy\\ImageExample\\" + to_string(i) + ".png";
		imwrite(ImgName2, img_final);
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值