防止越界,图像旋转带有缩放系数:
import cv2
import numpy as np
img = cv2.imread('face.jpg', 1)
cv2.imshow('src', img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
# (height * 0.5, width * 0.5): 图片中心点 旋转:45度 缩放:0.5
matRotate = cv2.getRotationMatrix2D((height * 0.5, width * 0.5), 45, 0.5 )
dst = cv2.warpAffine(img, matRotate, (height, width))
cv2.imshow('dst', dst)
cv2.waitKey(0)
结果如下:
image.png
网友评论