흑백
이미지를 흑백으로 읽음
import cv2
img = cv2.imread('../OpenCV/dog.jpg', cv2.IMREAD_GRAYSCALE)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
불러온 이미지를 흑백으로 변환
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
import cv2
img = cv2.imread('../OpenCV/dog.jpg')
dst = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('img',img)
cv2.imshow('gray',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
흐림
가우시안 블러
ker_3 = cv2.GaussianBlur(img, (3,3),0)
- 커널 크기는 홀수값, 양수
import cv2
img = cv2.imread('../OpenCV/dog.jpg')
ker_3 = cv2.GaussianBlur(img, (3,3),0)
ker_5= cv2.GaussianBlur(img, (5,5),0)
ker_7 = cv2.GaussianBlur(img, (7,7),0)
cv2.imshow('img',img)
cv2.imshow('ker_3',ker_3)
cv2.imshow('ker_5',ker_5)
cv2.imshow('ker_7',ker_7)
cv2.waitKey(0)
cv2.destroyAllWindows()
표준 편차
- sigmaX: 가우시안 커널의 x방향의 표준 편차
import cv2
img = cv2.imread('../OpenCV/dog.jpg')
sigma_1 = cv2.GaussianBlur(img, (0,0),1)
sigma_2= cv2.GaussianBlur(img, (0,0),2)
sigma_3 = cv2.GaussianBlur(img, (0,0),3)
cv2.imshow('img',img)
cv2.imshow('sigma_1',sigma_1)
cv2.imshow('sigma_2',sigma_2)
cv2.imshow('sigma_3',sigma_3)
cv2.waitKey(0)
cv2.destroyAllWindows()
원근
사다리꼴 이미지 평면으로
np.array([[511,352],[1008,345],[1152,584],[455,594]], dtype=np.float32)
matrix = cv2.getPerspectiveTransform(src, dst)
: Matrix 얻어옴
result = cv2.warpPerspective(img, matrix, (width, height))
: maatrix 대로 변환을 함
import cv2
import numpy as np
img = cv2.imread('../OpenCV/newspapper.jpg')
width, height = 640,240
src = np.array([[511,352],[1008,345],[1152,584],[455,594]], dtype=np.float32)
dst = np.array([[0,0],[width,0],[width,height],[0,height]], dtype=np.float32)
matrix = cv2.getPerspectiveTransform(src, dst)
result = cv2.warpPerspective(img, matrix, (width, height))
cv2.imshow('img',img)
cv2.imshow('result',result)
cv2.waitKey(0)
cv2.destroyAllWindows()