import cv2
import matplotlib.pyplot as plt
import numpy as np
#显示图片
def show(image):
plt.imshow(image)
plt.axis('off')
plt.show()
#读取图片,由BGR格式转换为RGB格式
def imread(image):
image = cv2.imread(image)
image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
return image
image = imread('jianghe.jpeg')
(h,w) = image.shape[:2]
#截取image.shape中前两个,刚好为高度和宽度
(cX,cY) = (w/2,h/2)
#cX,cY旋转中心点
#45---逆时针旋转45度
#-45---顺时针旋转45度
#1.0---缩放
M = cv2.getRotationMatrix2D((cX,cY),45,1.0)
image = cv2.warpAffine(image,M,(w,h))
show(image)
image = imread('jianghe.jpeg')
(h,w) = image.shape[:2]
#截取image.shape中前两个,刚好为高度和宽度
(cX,cY) = (w/2,h/2)
#cX,cY旋转中心点
#45---逆时针旋转45度
#-45---顺时针旋转45度
#2.0---缩放
M = cv2.getRotationMatrix2D((cX,cY),-45,2.0)
image = cv2.warpAffine(image,M,(w,h))
show(image)
image = imread('jianghe.jpeg')
(h,w) = image.shape[:2]
#截取image.shape中前两个,刚好为高度和宽度
(cX,cY) = (w/2,h/2)
#cX,cY旋转中心点
#45---逆时针旋转45度
#-45---顺时针旋转45度
#0.5---缩放
M = cv2.getRotationMatrix2D((cX,cY),-45,0.5)
image = cv2.warpAffine(image,M,(w,h))
show(image)
image = imread('jianghe.jpeg')
(h,w) = image.shape[:2]
#截取image.shape中前两个,刚好为高度和宽度
(cX,cY) = (w/2,h/2)
#cX-200,cY-200旋转中心点,大概为左上角区域
#45---逆时针旋转45度
#-45---顺时针旋转45度
#1.0---缩放
M = cv2.getRotationMatrix2D((cX-200,cY-200),45,1.0)
image = cv2.warpAffine(image,M,(w,h))
show(image)