import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img = cv.imread("../SampleImages/pomeranian.png", cv.IMREAD_COLOR)
#图像旋转
#Opencv中的旋转,首先通过cv.getRotationMatrix2D获得旋转矩阵
#cv.getRotationMatrix2D(center,angle,scale)
#center是旋转中心点,angle是旋转角度,scale是缩放比例
#参考资料:https://blog.csdn.net/qq_44109682/article/details/117434461
rows,cols = img.shape[:2]
M = cv.getRotationMatrix2D((cols/2,rows/2),45,1)
#然后用得到的旋转矩阵作为放射变换的M矩阵即可
#cv.warpAffine(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]])
# dsize是输出图像的大小,(宽度,高度),宽度是列数,高度是行数
#参考资料:https://blog.csdn.net/Gaowang_1/article/details/103128590
img_rotated = cv.warpAffine(img, M, (cols,rows))
fig,axes = plt.subplots(nrows=1, ncols=2, figsize=(10,10),dpi=100)
axes[0].imshow(img[:,:,::-1])
axes[0].set_title("Original")
axes[1].imshow(img_rotated[:,:,::-1])
axes[1].set_title("Rotated")
plt.show()