栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Resize and Crop

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Resize and Crop

The first thing is we are importing our image and now we are going to resize it. So to resize we have a function in opencv that helps us out, so we will write resize()

resize

(

InputArray 

src,//输入图像

OutputArray 

dst,//输出目标图像

Size 

dsize,//缩放后图像尺寸大小

double 

fx   0,//X方向上的缩放比例

double 

fy   0,//Y方向上的缩放比例

int 

interpolation   INTER_LINEAR//插值法 

)

and then we have to write the input image which is image, and then we have to write the output image we will call this imgResize, and let’s declare it mats imageResize (创建一个矩阵接收目标图像). So let’s say we will write size and what is the size of our image. At this point, how can we find that okay let me show you how we can do that. We are going to write cout and we will print out the size. So what we can do is let’s say we want a very specific number to resize, so what we can resize it. So let’s run that. We need to define a new window. Run it, and you can see that the aspect ratio has changed, it is not the same aspect ratio it’s squeezed a little bit with on the width. So if you don’t want to do that, if you don’t have a particular number, you just want to scale it down, then instead of using this size, you can remove this and you can define how much you want to scale so here you have doublefX and doublefY, so you can define here for example 0.5 and 0.5. so this will scale instead of exact pixels. So let’s have a look. And there you go so now it has decreased it 50 percent. So I mostly use the scaling part. Because

It is more convenient. Unless I have a very specific number that I want the image to be.

Now we will learn how to crop our images, because this is very important a lot of the times when we find an object we want to crop it to add more processing on that specific region and a lot of the times this region is called region of interest roi. So to crop an image we simply have to write let’s say that our new image is imageCrop. So we can define it here imageCrop. Inside we are going to define the values for cropping so to do that we are going to use the rectangle data type. So we will write here rect and then we will define a name. so let’s say roi and inside that we have to define the x, y, width and height.

Eg: Rect roi(100 ”X的起始坐标”,100 “Y的起始坐标”,600 “截取图像的宽”,600 “截取图像的高”)

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/268175.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号