소스 뷰어

직선 그리기

import numpy as np
import cv2
from matplotlib import pyplot as plt

green, red = (0, 255, 0), (255, 0, 0 )
image = np.zeros((400, 600,3), np.uint8)  # 3채널 영상
image[:] = 255 # 3채널 흰색

pt1, pt2 = (50, 50), (250, 150)
pt3, pt4 = (400, 150), (500, 50) 

cv2.line(image, pt1, pt2, red)
cv2.line(image, pt3, pt4, green, 3, cv2.LINE_AA) # 계산 현상 감소선

plt.imshow(image)
plt.show()
No description has been provided for this image

사각형 그리기

import numpy as np
import cv2
from matplotlib import pyplot as plt

import numpy as np
import cv2
from matplotlib import pyplot as plt

blue, green, red = (0, 0, 255), (0, 255, 0), (255, 0, 0 )
image = np.zeros((400, 600,3), np.uint8)  # 3채널 영상
image[:] = 255 # 3채널 흰색

pt1, pt2 = (50, 50), (250, 150)
pt3, pt4 = (400, 150), (500, 50) 
roi = (50, 200, 200, 100) # 시갹형 영역 = 4원소 튜플

cv2.rectangle(image, pt1, pt2, blue, 3, cv2.LINE_4) # 4방향 연결선
cv2.rectangle(image, roi, red, 3, cv2.LINE_8) # 8방향 연결선
cv2.rectangle(image, (400, 200, 100, 100), green, cv2.FILLED) # 내부채움

plt.imshow(image)
plt.show()
No description has been provided for this image