图像缩放¶
1. 倍数缩放¶
In [1]:
import cv2 #opencv的缩写为cv2
import matplotlib.pyplot as plt # matplotlib库用于绘图展示
import numpy as np # numpy数值计算工具包
# 魔法指令,直接展示图,Jupyter notebook特有
%matplotlib inline
In [2]:
img = cv2.imread('01_Picture/01_cat.jpg')
res = cv2.resize(img,(0,0),fx=3,fy=1) # (0,0)表示不确定具体值,fx=3 相当于行像素 x 乘 3,fy=1 相当于 y 乘 1
plt.imshow(res)
Out[2]:
<matplotlib.image.AxesImage at 0x2948bb84f28>
2. 等比例缩放¶
In [3]:
res = cv2.resize(img,(0,0),fx=1.5,fy=1.5) # 同比例放缩
plt.imshow(res)
Out[3]:
<matplotlib.image.AxesImage at 0x2948be20ef0>