import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
# 中文顯示配置
plt.rcParams['font.sans-serif']=['SimHei'] # 用來正常顯示中文標簽
plt.rcParams['axes.unicode_minus']=False # 用來正常顯示負號
# 載入圖片
img0 = cv.imread("img/img1.jpeg")
rows, cols = img0.shape[:2]
# 圖像旋轉
# 生成旋轉矩陣:旋轉中心,旋轉角度,縮放比例
M = cv.getRotationMatrix2D((cols/2,rows/2),90,1)
# 進行旋轉變換
dst = cv.warpAffine(img0,M,(cols,rows))
# 圖像展示
fig, axes = plt.subplots(nrows=1,ncols=2,figsize=(10,8),dpi=100)
axes[0].imshow(img0[:,:,::-1])
axes[0].set_title("原圖")
axes[1].imshow(dst[:,:,::-1])
axes[1].set_title("旋轉后結果")
plt.show()