앎을 경계하기

DAFIT/907 - OpenCV 다루기 첫걸음 7

<DAFIT> 07 OpenCV 다루기 첫걸음 - 07 영상 어파인 변환

import cv2 from google.colab.patches import cv2_imshow import numpy as np img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' 세 개의 꼭지점을 정해주면 getAffineTransform을 통해 이미지 변환을 할 수 있다. img = cv2.imread(img_path,1) height, width = img.shape[:2] controls = [] controls.append((0,0)) controls.append((0,height)) controls.append((width,0)) controls.append((width, height)) src = np.float32([list(co..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 06 영상 크기 조절

이번에는 resizing 문제이다. import cv2 from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' img = cv2.imread(img_path,1) height, width = img.shape[:2] down_img = cv2.resize(img,(height//2,width//2)) cv2_imshow(down_img) up_img = cv2.resize(img, (height*2, width*2)) cv2_imshow(up_img) img_list = [] for i in range(100): img_list.append(cv2.resize(img,(he..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 05 영상 뒤집기

이번에는 flip을 해보는 문제이다. import cv2 from google.colab.patches import cv2_imshow import numpy as np img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' flip함수는 사용하는 게 굉장히 쉽다. 1이면 좌우반전, 0이면 상하반전을 한다. img = cv2.imread(img_path,1) print('origin') cv2_imshow(img) v_img = cv2.flip(img, 1) print('\n\nvertical flip') cv2_imshow(v_img) h_img = cv2.flip(img, 0) print('\n\nhorizontal flip') cv2_imshow..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 04 영상 회전

지난번 translation에 이어 이번에는 rotation을 해보는 문제이다. import cv2 import numpy as np from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' angle을 지정해서 cv2.getRotationMatrix2D()를 사용해서 이미지의 중심점, 회전할 각도, 이미지크기(scale)을 넣어서 matrix를 구성해서 warpAffine에 넣어주면 된다. img = cv2.imread(img_path,1) rows, cols = img.shape[:2] angle = 90.0 M = cv2.getRotationMatrix2D((cols/2..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 03 영상 이동

사진을 이동시켜보는 문제이다. import cv2 import numpy as np from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' x축으로 50 ( 1, 0, 50 ), y축으로 50 ( 0, 1, 50 ) 이동해보자. img = cv2.imread(img_path,1) rows, cols = img.shape[:2] M = np.float32([[1,0,50],[0,1,50]]) img_result = cv2.warpAffine(img, M, (cols, rows)) cv2_imshow(img_result) 굉장히 쉽게 성공했다! http://www.dafit.m..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 02 영상 읽기, 출력, 저장

이번에는 이미지의 채널을 변환하고 분리하고 병합하는 것이다. import cv2 as cv from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' * 채널 변환 # OpenCV의 삼원색 기본 순서는 BGR이다. img_bgr = cv.imread(img_path,1) img_rgb = cv.cvtColor(img_rgb, cv.COLOR_BGR2RGB) cv2_imshow(img_bgr) cv2_imshow(img_rgb) * 채널 분리 및 병합 b,g,r = cv.split(img_bgr) img_rbg = cv.merge((r,b,g)) cv2_imshow(img_rbg..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 01 영상 읽기, 출력, 저장

이번 OpenCV 문제들은 lena 사진을 가지고 문제를 진행한다. 레나 이미지는 영상처리를 접해본 적 있다면 한번쯤 어디선가 다 봤을 것 같다. 코랩에서 진행해서 imshow()를 사용하려면 아래 import 과정이 필요하다. import cv2 as cv from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/DF907_01_01.jpg' #3채널로 이미지 읽기 img3 = cv.imread(img_path, flags=1) imread(이미지 경로, flags=-1,0,1 또는 enum constant) 1 = color 0 = grayscale -1 = alpha 채널 포함 열거형 상..