OpenCV的resize方法与双线性插值

六月 北京 | 高性能计算之GPU CUDA培训

6月22-24日 640?wx_fmt=jpeg 三天密集式学习  快速带你入门 阅读全文 >


正文共1328个字,3张图,预计阅读时间6分钟。


训练Object Detection模型SSD完毕之后进入test阶段,每张图像在进入输入层之前需要进行resize操作,以满足CNN模型对输入层size的要求。本文首先介绍了Caffe实现的SSD模型对输入图像的变换规定,引出了OpenCV中的resize方法,最后介绍该方法中的插值参数cv.INTER_LINEAR和该插值方法的原理。


caffe_ssd


caffe_ssd在test阶段,对图像的变换设置如下:


 1test_transform_param = {
2'mean_value': [104, 117, 123],
3'force_color': True,
4'resize_param': {
5        'prob': 1,
6        'resize_mode': P.Resize.WARP,
7        'height': resize_height,
8        'width': resize_width,
9        'interp_mode': [P.Resize.LINEAR],
10        },
11}


以上设定来自ssd_coco.py。


1、'mean_value': [104, 117, 123]是ImageNet图像BGR三个通道的均值。每张图像分别需要减去相应通道的均值,实现中心化。


2、'force_color': True强制采用彩色BGR图像模式,防止灰度图像维度与SSD模型输入层维度不一致。


3、resize_param属性在caffe.proto的ResizeParameter中有说明。


 1// Message that stores parameters used by data transformer for resize policy
2message ResizeParameter {
3//Probability of using this resize policy
4optional float prob = 1 [default = 1];
5enum Resize_mode {
6WARP = 1;
7FIT_SMALL_SIZE = 2;
8FIT_LARGE_SIZE_AND_PAD = 3;
9}
10optional Resize_mode resize_mode = 2 [default = WARP];
11optional uint32 height = 3 [default = 0];
12optional uint32 width = 4 [default = 0];
13// A parameter used to update bbox in FIT_SMALL_SIZE mode.
14optional uint32 height_scale = 8 [default = 0];
15optional uint32 width_scale = 9 [default = 0];
16enum Pad_mode {
17CONSTANT = 1;
18MIRRORED = 2;
19REPEAT_NEAREST = 3;
20}
21// Padding mode for BE_SMALL_SIZE_AND_PAD mode and object centering
22optional Pad_mode pad_mode = 5 [default = CONSTANT];
23// if specified can be repeated once (would fill all the channels)
24// or can be repeated the same number of times as channels
25// (would use it them to the corresponding channel)
26repeated float pad_value = 6;
27enum Interp_mode { //Same as in OpenCV
28LINEAR = 1;
29AREA = 2;
30NEAREST = 3;
31CUBIC = 4;
32LANCZOS4 = 5;
33 }
34//interpolation for for resizing
35repeated Interp_mode interp_mode = 7;
36}


其中的interp_mode采用LINEAR模式对图像进行Resize操作,与Opencv中的resize一致。


接下来,我们具体介绍一下OpenCV中的resize方法。


resize方法的签名

 1C++:   
2void cv::resize (InputArray src,
3OutputArray             dst,
4Size                      dsize,
5double                  fx = 0,
6double                  fy = 0,
7int                       interpolation = INTER_LINEAR
8)      
9Python:  
10dst =   cv.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])


参数说明:


 1src 输入图像.
2dst 输出图像; 其size为dsize,或由src.size()、fx与fy计算而得; dst类型与src保持一致.  
3dsize 输出图像的size; 如果设为0,或(0, 0), 计算方式为:
4
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值