center = width // 2, height // 2# 이미지의 중심 좌표
angle = 45# 회전 각도
ratio = 1# 확대 비율
matrix = cv.getRotationMatrix2D(center, angle, ratio) # 회전 행렬 계산
rotated = cv.warpAffine(image, matrix, (width, height)) # 이미지 회전
show(rotated) # 이미지 출력
크기 맞추기 및 배경 채우기
cos = abs(matrix [0, 0])
sin = abs(matrix [0, 1])
new_width = int((height * sin) + (width * cos)) # 새로운 너비
new_height = int((height * cos) + (width * sin)) # 새로운 높이
image_center = (width // 2, height // 2) # 원본 이미지의 중심 좌표
matrix [0, 2] += (new_width / 2) - image_center [0] # 새로운 x좌표로 이동
matrix [1, 2] += (new_height / 2) - image_center [1] # 새로운 y좌표로 이동
rotated = cv.warpAffine(
image, matrix,
(new_width, new_height), # 새로운 크기
borderMode=cv.BORDER_CONSTANT, # 배경 색은 한 가지로
borderValue=image[0, 0].tolist()) # 왼쪽 위 (0, 0)의 픽셀 값으로 배경을 채움
src_pts = pts1[:3].astype(np.float32) # 원본의 점 3개
dst_pts = pts2[:3] # 에 해당하는 변환된 점 3개
matrix = cv.getAffineTransform(src_pts, dst_pts)
dst = cv.warpAffine(src, matrix, (1000,1000))
show(dst)