目录
一、指定放缩比例
fx和fy是放缩的比例,前面的None占据的是明确规定的最后的大小,因为我们定义了比例,所以就不用规定最后的大小。
res = cv2.resize(img1,None,fx=2,fy=1,interpolation=cv2.INTER_CUBIC)
二、指定放缩到的长宽
规定的最后的大小需要是int型的。
(列,行)
res2 = cv2.resize(img1,(int(img1.shape[0]/2),int(img1.shape[1]/2)),interpolation=cv2.INTER_AREA)
三、interpolation插值
缩放有几种不同的插值(interpolation)方法
- 在缩小时推荐cv2.INTER_ARER
- 扩大是推荐cv2.INTER_CUBIC和cv2.INTER_LINEAR
- 默认都是cv2.INTER_LINEAR
四、代码
import cv2
img1 = cv2.imread('./Image/reba_color.jpg',cv2.IMREAD_COLOR)
res1 = cv2.resize(img1,None,fx=2,fy=1,interpolation=cv2.INTER_CUBIC)
res2 = cv2.resize(img1,(int(img1.shape[1]/2),int(img1.shape[0/2)),interpolation=cv2.INTER_AREA)
cv2.imshow('initial',img1)
cv2.imshow('large',res1)
cv2.imshow('small',res2)
cv2.waitKey(0)