목록Deep Learning (51)
Note
cv2.approxPolyDP(curve, epsilon, closed) 근사치 Contour 구하기 curve : Contour epsilon : 최대 거리(클수록 Point 개수 감소) closed : 폐곡선 여부 import cv2 import matplotlib.pyplot as plt image = cv2.imread('digit_image.png') image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(image_gray, 230, 255, 0) # 픽셀 값이 230 보다 큰 경우 255, 원본은 배경이 하얀색 thresh = cv2.bitwise_not(thresh) # 검정과 하얀색 반전 contou..
대략적인 형태 Contour 외곽 빠르게 구하기 cv2.convexHull(contour) Convex Hull 알고리즘으로 외곽을 구하는 함수 단일 contour 반환 import cv2 import matplotlib.pyplot as plt image = cv2.imread('digit_image.png') image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(image_gray, 230, 255, 0) # 픽셀 값이 230 보다 큰 경우 255, 원본은 배경이 하얀색 thresh = cv2.bitwise_not(thresh) # 검정과 하얀색 반전 contours = cv2.findContours(thres..
Contour의 사각형 외곽 찾기 cv2.boundingRect(contour) 사각형의 X,Y 좌표와 너비, 높이를 반환. import cv2 import matplotlib.pyplot as plt image = cv2.imread('digit_image.png') image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) ret, thresh = cv2.threshold(image_gray, 230, 255, 0) # 픽셀 값이 230 보다 큰 경우 255, 원본은 배경이 하얀색 thresh = cv2.bitwise_not(thresh) # 검정과 하얀색 반전 plt.imshow(cv2.cvtColor(thresh,cv2.COLOR_GRAY2RGB)) plt.sh..
이미지에서 Contour들을 찾는 함수 cv2.findContours(image, mode, method) mode : Contour들을 찾는 방법 - RETR_EXTERNAL :바깥쪽 Line만 찾기 - RETR_LIST : 모든 Line을 찾지만, Hierarchy 구성 X _ RETR_TREE : 모든 Line을 찾으며, 모든 Hierarchy 구성 O method : Contour들을 찾는 근사치 방법 - CHAIN_APPROX_NONE : 모든 Contour 포인트 저장 - CHAIN_APPROX_SIMPLE : Contour Line을 그릴 수 있는 포인트만 저장 입력 이미지는 Gray Scale Threshold 전처리 과정이 필요 Contour들을 그리는 함수 cv2.drawContours..
텍스트 그리기 cv2.putText(image, text, position, font_type, font_scale, color) position : 텍스트가 출력될 위치 font_type : 글씨체 font_scale : 글씨 크기 가중치 import cv2 import numpy as np import matplotlib.pyplot as plt image = np.full((512, 512, 3), 255, np.uint8) image = cv2.putText(image, 'Flask', (0, 200), cv2.FONT_ITALIC, 2, (255, 0, 0)) plt.imshow(image) plt.show()