■ getRotationMatrix2D 함수를 사용해 이미지를 회전하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import cv2 import numpy as np imageNDArray = cv2.imread("source.jpg") imageHeight, imageWidth = imageNDArray.shape[:2] matrixNDArray = cv2.getRotationMatrix2D((imageWidth / 2, imageHeight / 2), 90, 1) rotateImageNDArray = cv2.warpAffine(imageNDArray, matrixNDArray, (imageWidth, imageHeight)) cv2.imwrite("target.jpg", rotateImageNDArray) cv2.imshow("rotate image", rotateImageNDArray) cv2.waitKey(0) cv2.destroyAllWindows() |