Python:opencv画点、圆、线、多边形、矩形

# -*- coding: utf-8 -*-
import cv2.cv2 as cv2

img = cv2.imread(r"a.png")  # 读取图片

point_size = 1
point_color = (0, 0, 255)  # BGR
thickness = 2

# 画点
point = (100, 50)  # 点的坐标。画点实际上就是画半径很小的实心圆。
cv2.circle(img, point, point_size, point_color, thickness)

# 画圆
circle_point = (100, 100)
cv2.circle(img, circle_point, 20, point_color, thickness)

# 画线
cv2.line(img, (0, 0), (100, 100), color=(255, 0, 0), thickness=2)

# 画三角形:本质是多边形,即首尾相连的三条线。
cv2.line(img, (200, 200), (200, 300), color=(255, 0, 255), thickness=2)
cv2.line(img, (200, 300), (300, 300), color=(255, 0, 255), thickness=2)
cv2.line(img, (300, 300), (200, 200), color=(255, 0, 255), thickness=2)

# 矩形
cv2.rectangle(img, (715, 415), (830, 600), color=(0, 0, 255), thickness=2)


cv2.imshow("img", img)  # 展示结果
cv2.imwrite("label_data.png", img)  # 另存为
cv2.waitKey(4000)  # 展示多久后关闭。4000=4秒
cv2.destroyAllWindows()

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值