22 lines
641 B
Python
22 lines
641 B
Python
# -*- coding:utf-8 -*-
|
||
# @Author len
|
||
# @Create 2023/10/18 12:35
|
||
import cv2
|
||
import numpy as np
|
||
|
||
|
||
def rotate_image(image_path, angle):
|
||
# 读取图像
|
||
image = cv2.imread(image_path)
|
||
# 获取图像的尺寸和中心点
|
||
h, w = image.shape[:2]
|
||
center = (w // 2, h // 2)
|
||
# 获取旋转矩阵
|
||
M = cv2.getRotationMatrix2D(center=center, angle=-angle, scale=1.0)
|
||
# 进行仿射变换,borderValue设置为白色(255, 255, 255)
|
||
rotated_image = cv2.warpAffine(src=image, M=M, dsize=(w, h), borderValue=(255, 255, 255))
|
||
return rotated_image
|
||
|
||
tu = rotate_image('QR/1.jpg',15)
|
||
cv2.imshow("tu", tu)
|
||
cv2.waitKey() |