import numpy as np
import cv2
img = np.zeros((720,640,3), np.uint8)
cv2.line(img,(1,1),(360,560),(255,0,0),2)
#绘制线段
cv2.rectangle(img, (5,5),(240,180),(0,255,0),2)
#绘制矩形
cv2.circle(img,(300,300),100,(0,0,255),-1)
#绘制圆需要其中心坐标和半径
cv2.ellipse(img,(280,500),(120,80),180,0,180,(0,0,255),-1)
#绘制椭圆,一个参数是中心位置(x,y)。下一个参数是轴长度(长
#轴长度,短轴长度)。angle是椭圆沿逆时针方向旋转的角度。startAngle和endAngle表示从主轴
#沿顺时针方向测量的椭圆弧的开始和结束。即给出0和360给出完整的椭圆
pts = np.array([[120,150],[20,30],[170,120],[150,180]], np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img, [pts], True,(0,255,255),2)
#绘制三角形
triangles = np.array([[[60,180],[20,237],[100,237]]], np.int32)
cv2.fillPoly(img,triangles,(0,255,0))
####
#绘制任意图形
font = cv2.FONT_HERSHEY_SIMPLEX
#字体样式
cv2.putText(img,'Python-OpenCv',(10,600),font,2,(255,255,255),2,cv2.LINE_AA)
#坐标,字体样式,字体大小,颜色,厚度,线条样式
cv2.imshow('Plot',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
使用python opencv绘图
最新推荐文章于 2022-12-24 23:58:52 发布