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:“截取图像的高”)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值