cv.imread(filename, flags = None) -> retval
cv2.imwrite(filename, imgm params = None) -> retval
cv2.nameWindow(winname, flags = None) -> None
cv2.destroyWindow winname() -> None
cv2.destroyAllWindows() -> None
참고사항
cv2.moveWindow winname , x , y ) --> None
cv2.resizeWindow winname , width , height ) --> None
참고사항
cv2.imshow(winname , mat) --> None
참고사항
cv2.waitKey(delay = None) --> retval
# 컬러로 읽기
img_color = cv2.imread(img_path, cv2.IMREAD_COLOR)
#흑백 이미지로 읽기
img_gray = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
cv2.imread(filename, flag)
인자
#컬러 이미지 행렬 차원 확인하기
print(type(img_color), img_color.shape)
#흑백 이미지 행렬 차원 확인하기
print(type(img_gray), img_gray.shape)
if cv2.imwrite(save_path, img_gray):
print("image save done")
else
print("image save failed")
cv2.imwrite(filename, image)
인자
fileName:문자열 타입의 파일경로
image:numpy.ndarray 타입 이미지
반환값 : 이미지 저장 실패 여부가 bool 타입으로 반환
# 흑백 이미지를 다시 컬러 이미지로 바꾸기
img_gray_to_color = cv2.cvColor(img_gray, cv2.COLOR_GRAY2BGR)
# 흑백 이미지 컬로 변환 후 행렬 차원 확인하기
print("흑백 이미지를 다시 컬러로 변환 : ", type(img_gray_to_color),img_gray_to_color.shape)
cv2.cvtColor(image,option)
인자
image : numpy.ndarray 타입 이미지
option : 이미지를 읽을 떄 사용할 옵션
반환값 : 이미지를 제대로 읽으면 numpy.ndarray 타입의 이미지가, 그렇지 못할 경우 None을 반환
#이미지 리사이징 하기
img_resized = cv2.resize(img_color,(512,512))
print("이미지를 512 x 512로 크기 변환 :", type(img_resized), img_resized.shape)
cv2.resize(image, dsize)
인자
image : numpy, ndarray 타입 이미지
dsize : 목적 이미지 크기 , 튜플 형태로 (가로 세로) 로 지정
반환값 : 이미지를 제대로 읽으면 numpy.ndarray 타입의 이미지가 그렇지 못할 경우 None을 반환
img_croped = img_color[0:img_color.shape[0] //2, :]
print("이미지를 횡으로 크롭하기: ", type(img_croped), img_croped.shape)
크롭 = 2차원 배열을 슬라이싱 하는 것
OpenCV는 이미지를 행렬로 다루므로
numpy의 슬라이싱 기능을 그대로 쓸 수 있음
image_cropped = [시작행:종료행, 시작열:가로열]