opencv+python(图形绘制)

发布于:2024-04-08 ⋅ 阅读:(141) ⋅ 点赞:(0)

1、画直线

 line(img: ndarray,
         pt1: Sequence[int],#起点
         pt2: Sequence[int],#终点
         color: Sequence[float],#颜色
         thickness: int = ...,#宽度
         lineType: int = ...,# 线形
         shift: int = ...)# 缩放比

2、画矩形

cv2.rectangle(img,(150,150),(300,300),(0,0,255),5,8)
  cv2.line(img,(150,150),(300,300),(0,0,255),5,4)  
  cv2.rectangle(img,(150,150),(300,300),(0,0,255),5,8)

   cv2.imshow("img",img)
   cv2.waitKey(0)

3、画圆

circle(img: ndarray,
           center: Sequence[int], #圆心
           radius: int,  #半径
           color: Sequence[float],
           thickness: int = ...,
           lineType: int = ...,
           shift: int = ...

 cv2.circle(img,(150,150),100,(0,0,255),5,8)

4、画椭圆

 ellipse(img: ndarray,
            center: Sequence[int],#圆心
            axes: Sequence[int],#轴半径的x与y
            angle: float,  #角度
            startAngle: float,#起始角度
            endAngle: float,#终点角度 注意是逆时针旋转的
            color: Sequence[float],
            thickness: int = ...,
            lineType: int = ...,
            shift: int = ...)

cv2.ellipse(img,(150,150),(50,150),0,0,360,(0,0,255))

5、多边形绘制

 polylines(img: ndarray,
             [pts]: Sequence[ndarray],#各个点的坐标,这个地方[]不能省略
              isClosed: bool,
              color: Sequence[float],
              thickness: int = ...,
              lineType: int = ...,
              shift: int = ...)

pts =np.array([(250,250),(150,150),(100,50),(150,0),(250,250)],np.int32)
cv2.polylines(img,[pts],True,(0,0,255))

cv2.fillPoly(img,[pts],(0,0,255)) #填充颜色


网站公告

今日签到

点亮在社区的每一天
去签到