代码位置:6-ImageRotation.py
import cv2
img = cv2.imread('./res/aero3.jpg')
print(img.shape[:2])
height, width = img.shape[:2]
M = cv2.getRotationMatrix2D((width/2, height/2), 90*2, 1)
img_ro = cv2.warpAffine(img, M, (width, height))
cv2.imshow('rotation', img_ro)
cv2.waitKey()
cv2.destroyAllWindows()
getRotationMatrix2D为计算旋转的规则,第一个参数是旋转的中心轴,此处为图片正中,第二个参数是旋转角度,这里是45度。第三个参数是同向性缩放参数,填写1就可以了。