728x90
import numpy as np
from PIL import ImageFont, ImageDraw, Image
import cv2
# cv2 Mat 타입 사용
img = cv2.imread("./Lenna.png")
# cv2 -> PIL 이미지로 변경
color_coverted = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_pil=Image.fromarray(color_coverted)
# PIL 이미지에 한글 입력
draw = ImageDraw.Draw(img_pil)
draw.text((10, 10), "안녕하세요!", font=ImageFont.truetype("./malgun.ttf", 48), fill=(255,255,255))
# PIL 이미지 -> cv2 Mat 타입으로 변경
numpy_img = np.array(img_pil)
cv_img = cv2.cvtColor(numpy_img, cv2.COLOR_RGB2BGR)
# 변경된 cv2 Mat 타입 출력
cv2.imshow("test", cv_img)
cv2.waitKey()
실행 결과
'Python' 카테고리의 다른 글
ellipsis(...) (0) | 2022.01.19 |
---|---|
Tensorflow + Alexnet(2012) (0) | 2021.11.15 |
Visual Studio 2022 + Python3.9.5(64bit) (0) | 2021.11.15 |
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized. (0) | 2021.10.15 |