728x90
목표
- cv.line, cv.circle, cv.rectangle, cv.elipse, cv.putText 사용하기
Drawing Line
import numpy as np
import cv2 as cv
img = np.zeros((512, 512, 3), np.uint8)
cv.line(img, (0, 0), (511, 511), (255, 0, 0), 5)
cv.imshow("draw", img)
cv.waitKey(0)
np를 사용해서 Mat을 만들었다.
line 인수는 순서대로 Mat, 첫번째 포지션, 두 번째 포지션, BGR컬러, 두께이다.
Drawing Rectangle
import numpy as np
import cv2 as cv
img = np.full((512, 512, 3), 255, np.uint8)
cv.rectangle(img, (510, 128), (384, 0), (0, 255, 0), 3)
cv.imshow("draw", img)
cv.waitKey(0)
np.full을사용해서 값이 255인 하얀색 바탕을 만들었다.
rectange의 인수는 순서대로 Mat, 하나의 포지션, 대각선 포지션, 색상, 두께이다.
Drawing Circle
import numpy as np
import cv2 as cv
img = np.full((512, 512, 3), 255, np.uint8)
cv.circle(img,(447,63), 63, (0,0,255), -1)
cv.imshow("draw", img)
cv.waitKey(0)
circle의 인수는 순서대로 Mat, 중심 포지션, 반지름 길이, 색상, 두께이다.
두께에 -1을넣으면 색상이 있는 원이 된다.
Drawing Ellipse
import numpy as np
import cv2 as cv
img = np.full((512, 512, 3), 255, np.uint8)
cv.ellipse(img,(256,256),(100,50),0,0,360,(0,255,0),-1)
cv.imshow("draw", img)
cv.waitKey(0)
Ellipse 인수는 순서대로 Mat, 중심 포지션, 출의길이(장축, 단축), 회전(시계 반대방향), 그려지는 시작각도, 그려지는 끝 각도, 색상, 두께이다.
Drawing Polygon
import numpy as np
import cv2 as cv
img = np.zeros((512, 512, 3), np.uint8)
pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)
pts = pts.reshape((-1,1,2))
cv.polylines(img,[pts],True,(255,255,255))
cv.imshow("draw", img)
cv.waitKey(0)
numpy를 통해 path를 만들어준다.
polylines의 인수는 Mat, path, 닫을건지 아닐건지, 색상이다.
'언어 > OpenCV(Python)' 카테고리의 다른 글
[OpenCV]색공간 변경 (0) | 2022.03.23 |
---|---|
[OpenCV]이미지 연산 (0) | 2022.03.22 |
[OpenCV]이미지의 기본연산 (0) | 2022.03.21 |
[OpenCV]비디오 가져오기 (0) | 2022.03.17 |
[OpenCV]이미지 가져오기 (0) | 2022.03.16 |