绘制直线
函数:cv2.line(img,Point pt1,Point pt2,color,thickness=1,line_type=8 shift=0)这个函数主要接受參数为两个点的坐标,线的颜色
import cv2
import numpy as np
convas = img = np.zeros((1080,1080,3),np.uint8)
convas.fill(255)
cv2.line(convas,(0,0),(511,511),(0,255,0),1) #画绿线
cv2.imshow('line',convas)
绘制矩形
函数:cv2.rectangle(img,(380,0),(511,111),(255,0,0),3),须要确定的就是矩形的两个点(左上角与右下角)。颜色,线的类型。
convas = img = np.zeros((1080,1080,3),np.uint8)
convas.fill(255)
cv2.rectangle(convas,(30,30),(512,512),(0,0,255),2)
cv2.imshow('rectangle',convas)
绘制圆形
函数:cv2.circle (img,point,radius,(255,0,0),1),参数为图像,圆心,半径,颜色,线的粗细(-1表示实心圆)
convas = img = np.zeros((1080,1080,3),np.uint8)
convas.fill(255)
cv2.circle(convas,(30,30),90,(0,0,255),2)
cv2.imshow('circle',convas)
绘制椭圆
函数:cv2.ellipse(img, center, axes, rotateAngle, startAngle, endAngle, color[, thickness[, lineType[, shift]]])
img:要画的圆所在的矩形或图像
center:椭圆的中心点
axes:椭圆的长半轴和短半轴的大小
rotateAngle:椭圆的旋转角度
startAngle:椭圆弧的起始角度
endAngle:椭圆弧的终止角度
color:线条颜色,如 (0, 0, 255) 红色,BGR
thickness:线条宽度
lineType:
8 (or omitted) : 8-connected line
4:4-connected line
CV_AA - antialiased line
shift:坐标点小数点位数
convas = img = np.zeros((1080,1080,3),np.uint8)
convas.fill(255)
cv2.ellipse(convas,center=(30,30),axes=(),(0,0,255),2)
cv2.imshow('ellipse',convas)