numpy 라이브러리 활용, 빈 캔버스(도화지) 생성import cv2
import numpy as np
bg = np.zeros(
shape=(500, 500, 3),
dtype=np.uint8
)
bg[:,:,0] = 220
bg[:,:,1] = 221
bg[:,:,2] = 217
cv2.imwrite("./data/bg.jpg", bg)

rectangle() 활용rect = cv2.rectangle(
img=bg,
pt1=(150, 150),
pt2=(350, 350),
color=(255, 0, 0),
thickness=3, # -1 지정 시 내부가 채워진 도형 생성
)
cv2.imwrite("./data/rect.jpg", rect)

circle() 활용circle = cv2.circle(
img=bg,
center=(250, 250),
radius=50,
color=(0, 100, 0),
thickness=2,
)
cv2.imwrite("./data/circle.jpg", circle)

ellipse() 활용ellipse = cv2.ellipse(
img=bg,
center=(250, 250),
axes=(200, 150),
angle=45,
startAngle=0,
endAngle=360,
color=(0, 0, 150),
thickness=0,
)
cv2.imwrite("./data/ellipse.jpg", ellipse)

polylines() 활용pts = np.array(
[[250, 150], [150, 350], [350, 350]],
)
triangle = cv2.polylines(
img=bg,
pts=[pts],
isClosed=True,
color=(100, 0, 100),
thickness=3,
)
cv2.imwrite("./data/triangle.jpg", triangle)

img = cv2.imread("data/night_sky.jpg")
text = "Night Sky"
font = cv2.FONT_HERSHEY_SIMPLEX
pos = (50, 200)
font_scale = 5
color = (255, 255, 255)
thickness = 2
img_txt = cv2.putText(img, text, pos, font, font_scale, color, thickness)
cv2.imwrite("data/night_sky_txt.jpg", img_txt)

*이 글은 제로베이스 데이터 취업 스쿨의 강의 자료 일부를 발췌하여 작성되었습니다.