import numpy as np
import imutils
import cv2
from PIL import Image
image = cv2.imread("img/woman_side_portrait.jpg")
(height, width, channels) = image.shpe
images = []
for angle in np.arange(0, 360, 15):
rotated = imutils.rotate(image, angle)
images.append(Image.fromarray(cv2.cvtColor(rotated,cv2.COLOR_BGR2RGB)))
# cv2.imshow("Rotated", rotated)
# cv2.waitKey(0)
images[0].save("img/rotated_cutoff.gif",save_all=True,loop=True,append_images=images[1:],duration=500)
images1 = []
for angle in np.arange(0, 360, 15):
rotated = imutils.rotate_bound(image, angle)
height = height if rotated.shape[0] < height else rotated.shape[0]
width = width if rotated.shape[1] < width else rotated.shape[1]
# cv2.imshow("Rotated", rotated)
# cv2.waitKey(0)
images1.append(Image.fromarray(cv2.cvtColor(rotated, cv2.COLOR_BGR2RGB)))
my_img = np.zeros((height, width, channels), dtype = "uint8")
my_img.save("img/rotated_ncutoff.gif",save_all=True,loop=True,append_images=images1[:],duration=500)
Rotate images (correctly) with OpenCV and Python
python+opencv+图像几何变换(图片缩放、剪切、位移、镜像,放射变换,旋转)