#首先使用OpenCV顺时针旋转图像45度,计算图像中心,然后构造旋转矩阵,然后最后应用仿射经线。
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, -45, 1.0)
rotated = cv2.warpAffine(image, M, (w, h))
cv2.imshow("OpenCV Rotation", rotated)
cv2.waitKey(0)
现在我们使用imutils库函数一行代码就可以实现旋转:
通过imutils也可以用更少的代码轻松地完成旋转:
rotated = imutils.rotate(image, -45)
cv2.imshow("Imutils Rotation", rotated)
cv2.waitKey(0)