OpenCV-3之draw_shape

本文介绍了使用Python结合OpenCV库进行图像处理的方法,详细展示了如何利用cv2.line、cv2.circle、cv2.rectangle等函数绘制直线、圆、矩形等基本形状,并介绍了如何用cv2.putText函数为图像添加文本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、cv2.line

import cv2
img = cv2.imread(r"img/1.jpg")

cv2.line(img, pt1=(100, 30), pt2=(210, 180), color=(0, 0, 255), thickness=2) 
cv2.imshow("pic show", img)
cv2.waitKey(0)

2、cv2.circle:thickness=-1,内部填充

import cv2
img = cv2.imread(r"img/1.jpg")

cv2.circle(img, center=(50, 50), radius=30, color=(0, 0, 255), thickness=2) 
cv2.imshow("pic show", img)
cv2.waitKey(0)

3、cv2.rectangle:thickness=-1,内部填充

cv2.rectangle(img, pt1=(100, 30), pt2=(210, 180), color=(0, 0, 255), thickness=2)

4、cv2.ellipse:thickness=-1,内部填充

cv2.ellipse(img, center=(100, 100), axes=(100, 50), angle=0, startAngle=0, endAngle=360, color=(255, 0, 0), thickness=-1)

5、cv2.polylines:[pts],否则点不连城线,thickness不能取负数

pts = np.array([[10, 5], [50, 10], [70, 20], [20, 30]], np.int32)
pts = pts.reshape((-1, 1, 2))  # shape[4, 1, 2]
cv2.polylines(img, [pts], isClosed=True, color=(0, 0, 255), thickness=2)

6、cv2.putText

# org:Bottom-left corner of the text string in the image
# lineType=cv2.LINE_AA:抗锯齿
cv2.putText(img, text='beautiful girl', org=(10, 30), fontFace=cv2.FONT_HERSHEY_SIMPLEX, 
            fontScale=1, color=(0, 0, 255), thickness=1, lineType=cv2.LINE_AA)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值