import numpy as np
import cv2 as cv
# Create a black image
img = np.zeros((512, 512, 3), np.uint8)
np.zeros()
函数创建一个都是0的多元数组,可以理解为512行、512列、每格中有三个0,引入cv.imshow
,之后,是一个512*512的黑色图片,每格中的三个0对应BGR,改变数值则会改变颜色
cv.line(img, (0,0), (511,511), (255,0,0), 5)
cv.line(img, pt1, pt2, color[, thickness[, lineType[, shift]]])
cv.line(img, (10,500), (500,10), (255,0,0), 5, cv.LINE_AA, 1)
等价于
cv.line(img, (5,250), (250,5), (255,0,0), 5, cv.LINE_AA, 0)
cv.rectangle(img, (384,0), (510,128), (0,255,0), 3)
cv.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]] )
cv.circle(img,(447,63), 63, (0,0,255), -1)
cv.circle(img, center, radius, color[, thickness[, lineType[, shift]]] )
cv.ellipse(img,(256,256),(100,50),0,0,180,(255,0,0), -1)
cv.ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[, lineType[, shift]]])
pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)
pts = pts.reshape((-1,1,2))
cv.polylines(img,[pts],True,(0,255,255))
cv.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]])
reshape()函数,详见https://www.zhihu.com/question/52684594
font = cv.FONT_HERSHEY_SIMPLEX
cv.putText(img, 'OpenCV', (10,500), font, 4, (255,255,255), 2, cv.LINE_AA)
cv.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])