영상의 회전

매일 공부(ML)·2021년 11월 29일
0

OPEN CV

목록 보기
26/45

영상의 회전

  • 회전 변환(rotation transformation)

    • 영상을 특정 각도만큼 회전(반시계 방향)

  • 예제
src = cv2.imread('tekapo.bmp')

rad = 20 * math.pi / 180

aff = np.array([[math.cos(rad), math.sin(rad), 0],
				[-math.sin(rad), math.cos(rad), 0]], dtype=np.float32)

dst = cv2.warpAffine(src, aff, (0, 0))

  • 영상의 회전 변환 행렬 구하기
cv2.getRotationMatrix2D(center, angle, scale) -> retval
  • center: 회전 중심 좌표(x,y)튜플

  • angle: (반시계방향) 회적 각도로 음수는 시계 방향이다

  • scale: 추가적인 확대 비율

  • retval: 2 * 3 어파인 변환 행렬로 실수형이다.

  • 중앙 기준 회전 예제
src = cv2.imread('tekapo.bmp')

cp = (src.shape[1] / 2, src.shape[0] / 2)
rot = cv2.getRotationMatrix2D(cp, 20, 1)

dst = cv2.warpAffine(src, rot, (0, 0))

profile
성장을 도울 아카이빙 블로그

0개의 댓글