OpenCV

rotate / warpAffine/ getAffine 이미지 돌리기

728x90
import cv2

source = cv2.imread('data/images/sample.jpg', 1)

# 회전의 중심좌표
center = (source.shape[1]/2, source.shape[0]/2)
rotationAngel = 15
scaleFactor = 1

rotationMatrix = cv2.getRotationMatrix2D(center, rotationAngel, scaleFactor)

print(rotationMatrix)

result = cv2.warpAffine(source, 
                        rotationMatrix, 
                        (source.shape[1], source.shape[0]) )

cv2.imshow('Original', source)
cv2.imshow('Rotated Image', result)

cv2.waitKey(0)
cv2.destroyALLWindow()

import cv2
import numpy as np

source = cv2.imread('data/images/sample.jpg',1)

warpMat = np.float32([1.2,0.2,2,-0.3,1.3,1])
warpMat = warpMat.reshape(2,3)

result = cv2.warpAffine(source, warpMat, 
                        (int(source.shape[1]*1.5), int(source.shape[0]*1.5)))


warpMat2 = np.float32([1.2,0.3,2,0.2,1.3,1])
warpMat2 = warpMat.reshape(2,3)

result2 = cv2.warpAffine(source, warpMat, 
                        (int(source.shape[1]*1.5), int(source.shape[0]*1.5)))

cv2.imshow('original', source)  
cv2.imshow('result', result)
cv2.imshow('result', result2)
cv2.waitKey(0)
cv2.destroyALLWindow()

import cv2
import numpy as np

input_tri = np.float32( [ 50,50 , 100,100 , 200,150 ] )
#원본 이미지의 삼각형의 점임 [50,50],[100,100],[200,150]
input_tri = input_tri.reshape(3,2)

#변환된 이미지의 2점의 좌표
output_tri = np.float32( [ 70,76,142,101,272,136 ] )
#세 점의 좌표로 변경
output_tri = output_tri.reshape(3,2)
print(input_tri)
print(output_tri)

warpMat = cv2.getAffineTransform(input_tri, output_tri)
print(warpMat)

728x90

'OpenCV' 카테고리의 다른 글

perspective Correction(클릭해서 이미지 추출)  (0) 2021.04.20
homography_book  (0) 2021.04.20
opening, closing  (0) 2021.04.20
erode 이미지 침식  (0) 2021.04.20
dilate 이미지 확장  (0) 2021.04.20