查看: 1597|回复: 0

CV2.resize()详解

[复制链接]

665

主题

1234

帖子

6586

积分

xdtech

Rank: 5Rank: 5

积分
6586
发表于 2020-4-25 09:18:07 | 显示全部楼层 |阅读模式
cv2.resize(src,dsize,dst=None,fx=None,fy=None,interpolation=None)

scr:原图

dsize:输出图像尺寸

fx:沿水平轴的比例因子

fy:沿垂直轴的比例因子

interpolation:插值方法
例子:
im = cv2.resize(im, self.resize_h_w[::-1], interpolation=cv2.INTER_LINEAR)
这里声明的im为原图
self.resize_h_w[::-1]为裁剪后的图像大小,self.resize_h_w[::-1]这里应该是将h和w数组的值反过来。
这里采用的线性插值。


  • img = cv2.imread("lena.jpg", -1)  
  •     if img == None:  
  •         print "Error: could not load image"  
  •         os._exit(0)  
  •     height, width = img.shape[:2]  
  •     # 缩小图像  
  •     size = (int(width*0.3), int(height*0.5))  
  •     shrink = cv2.resize(img, size, interpolation=cv2.INTER_AREA)
  •     # 放大图像  
  •     fx = 1.6  
  •     fy = 1.2  
  •     enlarge = cv2.resize(img, (0, 0), fx=fx, fy=fy, interpolation=cv2.INTER_CUBIC)  
  •     # 显示  
  •     cv2.imshow("src", img)  
  •     cv2.imshow("shrink", shrink)  
  •     cv2.imshow("enlarge", enlarge)  
  •     cv2.waitKey(0)  

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表