简介
想要完成这样一个功能,输入一个图像,输入旋转中心和角度。完成对该图像的旋转。
代码如下
import cv2
import numpy as np
from matplotlib import pyplot as plt
if __name__ == "__main__":
file = r'D:\dataset\IMG_0003_corr.png'
im = cv2.imread(file, 1)[..., ::-1]
h, w, c = im.shape
theta1 = 107 # 顺时针旋转角度,单位为角度
x0, y0 = w // 2, h // 2 # 以图像中心作为旋转中心
M = cv2.getRotationMatrix2D((x0, y0), theta1, 1.0)
out = cv2.warpAffine(im, M, (w, h)) # 旋转变换,默认为黑色填充
plt.figure()
plt.imshow(np.hstack((im,out)))
plt.show()