소스 뷰어
import cv2
import numpy as np
import matplotlib.pyplot as plt

# lena.jpg 이미지를 로드하고 RGB로 변환
image = cv2.imread('lena.jpg')
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# 회전 변환 행렬 정의
angle = 45  # 회전 각도 (45도)
scale = 1.0  # 스케일 (크기 비율)

# 이미지의 중심 계산
(h, w) = image_rgb.shape[:2]
center = (w // 2, h // 2)

# 회전 변환 행렬 생성
rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)

# 회전 적용
rotated_image = cv2.warpAffine(image_rgb, rotation_matrix, (w, h))

# 원본 이미지와 회전된 이미지를 출력
plt.figure(figsize=(10, 5))
fs = 20  # 폰트 사이즈

# 원본 이미지
plt.subplot(1, 2, 1)
plt.imshow(image_rgb)
plt.title("Original Image", fontsize=fs)
plt.axis("off")

# 회전된 이미지
plt.subplot(1, 2, 2)
plt.imshow(rotated_image)
plt.title(f"Rotated Image (OpenCV)", fontsize=fs)
plt.axis("off")

plt.tight_layout()
plt.show()
No description has been provided for this image