본문 바로가기
OpenCV

[OpenCV] draw.py

by Lizardee 2024. 4. 10.
import cv2 as cv
import numpy as np

# Blank image
# np.zeros: height, weight, number of color channels
blank = np.zeros((500,500,3), dtype='uint8')
cv.imshow('Blank', blank)


# 1. Paint the image a certain color (BGR)
blank[200:300, 300:400] = 0,255,0
cv.imshow('Green', blank)


# 2. Draw a rectangle
cv.rectangle(blank, (0,0), (250,500), (0,255,0), thickness=2)
cv.imshow('Rectangle', blank)


# 3. Draw a circle
cv.circle(blank, (250,250), 40, (0,0,255), thickness=3)
cv.imshow('Circle', blank)


# 4. Draw a line
cv.line(blank, (0,0), (250,250), (255,255,255), thickness=3)
cv.imshow('Line', blank)


# 5. Write text
cv.putText(blank, 'Hello', (255,255), cv.FONT_HERSHEY_TRIPLEX, 1.0, (255,255,255), thickness=2)
cv.imshow('Text', blank)

cv.waitKey(0)

'OpenCV' 카테고리의 다른 글

[OpenCV] contours.py  (0) 2024.04.10
[OpenCV] transformations.py  (0) 2024.04.10
[OpenCV] basic.py  (0) 2024.04.10
[OpenCV] rescale.py  (0) 2024.04.10
[OpenCV] read.py  (0) 2024.04.10