关于GitHub@ShaneHolmes_OpenCV_image_rotation
源代码:
import cv2
img = cv2.imread('C://Users//47463//Desktop//2//cat.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就可以了
- cv2.warpAffine进行旋转,第一个参数是img,第二个是旋转的规则,第三个是图像的尺寸大小
更多文章:https://blog.csdn.net/qq_33208851/article/details/95237054