opencv-python 图像 二

http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_drawing_functions/py_drawing_functions.html
直线
cv2.line(img,(起始点),(终点),(颜色),px大小)

颜色为 bgr
>>> import cv2
>>> import numpy as np
>>> img=np.zeros((512,512,3),np.uint8)
>>> img = cv2.line(img,(0,0),(511,511),(255,0,0),5)
>>> cv2.imshow("xx",img)

矩形
img=cv2.rectangle(img,(384,0),(510,128),(0,255,0),3)

需要指定左上角,到右下角的坐标,颜色,px大小
>>> img=cv2.rectangle(img,(384,0),(510,128),(0,255,0),3)
>>> cv2.imshow("xx",img)


img = cv2.circle(img,(447,63), 63, (0,0,255), -1)

需要注意的是 -1代表内切圆
image.png

椭圆
img = cv2.ellipse(img,(256,256),(100,50),0,0,180,255,-1)

未试过

多边形
pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)
pts = pts.reshape((-1,1,2))
img = cv2.polylines(img,[pts],True,(0,255,255))

未试过
To draw a polygon, first you need coordinates of vertices. Make those points into an array of shape ROWSx1x2 where ROWS are number of vertices and it should be of type int32. Here we draw a small polygon of with four vertices in yellow color.

添加文字
cv2.putText()

但是显示中文的貌似没有对应的字体,不知道该怎么添加
Text data that you want to write
Position coordinates of where you want put it (i.e. bottom-left corner where data starts).
Font type (Check cv2.putText() docs for supported fonts)
Font Scale (specifies the size of font)
regular things like color, thickness, lineType etc. For better look, lineType = cv2.LINE_AA is recommended.

font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img,'OpenCV',(10,500), font, 4,(255,255,255),2,cv2.LINE_AA)

你可能感兴趣的:(opencv-python 图像 二)