opencv 的resize 和numpy 的reshape 中 ,高和宽位置的区别

今天在处理图片的时候,遇到了两行代码,就是先resize图片,在加一个维度。执行发现出了问题,代码如下:

img = cv2.resize(img, (image_height,image_width ),interpolation=cv2.INTER_CUBIC)
img = np.reshape(img, [image_height, image_width, image_channel])

隐约估计是宽高的顺序问题,经过查文档,其中,resize的文档如下:

resize
Resizes an image.
C++: void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR )¶
Python: cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) → dst
C: void cvResize(const CvArr* src, CvArr* dst, int interpolation=CV_INTER_LINEAR )
Python: cv.Resize(src, dst, interpolation=CV_INTER_LINEAR) → None
Parameters:
src – input image.
dst – output image; it has the size dsize (when it is non-zero) or the size computed from src.size(), fx, and fy; the type of dst is the same as of src.
dsize –
output image size; if it equals zero, it is computed as:
\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}
Either dsize or both fx and fy must be non-zero.

也就是说resize 是默认的先fx轴,后fy轴,也就是先宽后高

但是numpy中的reshape,是指矩阵中的(行,列),对应图片就是(高,宽)

#img = cv2.resize(img, (image_height,image_width ),interpolation=cv2.INTER_CUBIC)
img = cv2.resize(img, (image_width ,image_height),interpolation=cv2.INTER_CUBIC)
img = np.reshape(img, [image_height, image_width, image_channel])

图片中关于size或shape的操作经常变,需要多多注意

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值