import cv2 import numpy as np iamge_path = 'xuanzhu.jpg' # 顺时针旋转90度 def RotateClockWise90(img): trans_img = cv2.transpose(img) new_img = cv2.flip(trans_img, 1) return new_img # 逆时针旋转90度 def RotateAntiClockWise90(img): trans_img = cv2.transpose(img) new_img = cv2.flip(trans_img, 0) return new_img
def image_porcess(): from PIL import Image import matplotlib.pyplot as plt img = Image.open(iamge_path) # 打开图片 # 逆时针旋转45度 (有黑色背景) img01 = img.rotate(45) plt.imshow(img01) plt.show() # 无黑色背景 img02 = img.transpose(Image.ROTATE_90) plt.imshow(img02) plt.show()