cv2.rectangle(),绘制矩形。
void cv::rectangle ( InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
Python:
img = cv.rectangle( img, pt1, pt2, color[, thickness[, lineType[, shift]]] )
img = cv.rectangle( img, rec, color[, thickness[, lineType[, shift]]] )
In [1]: import cv2
In [2]: import numpy as np
In [3]: img=np.zeros((512,512,3),np.uint8)
In [4]: cv2.rectangle(img,(300,0),(410,128),(0,255,0),3)
In [5]: winname = 'example'
...: cv2.namedWindow(winname)
...: cv2.imshow(winname, img)
...: cv2.waitKey(0)
...: cv2.destroyWindow(winname)
类似cv2.line()、cv2.circle()、cv2.ellipse()、cv2.putText()等都是这么画的,只不过cv2.rectangle()用的比较多一些,还有cv2.polylines()。
void cv::polylines ( InputOutputArray img,
InputArrayOfArrays pts,
bool isClosed, # 闭环
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0
)
Python:
img = cv.polylines( img, pts, isClosed, 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))
font = cv.FONT_HERSHEY_SIMPLEX
cv.putText(img,'OpenCV',(10,500), font, 4,(255,255,255),2,cv.LINE_AA)
# 要画圆的话,只需要指定圆形的中心点坐标和半径大小。我们在上面的矩形中画一个圆。
cv.circle(img,(447,63), 63, (0,0,255), -1)
cv.ellipse(img,(256,256),(100,50),0,0,180,255,-1)