import numpy as np
import cv2
# 1.画直线
img = np.zeros((512, 512, 3), np.uint8)
# print(type(img))
# print(img)
cv2.line(img, (100,100), (511, 511), (255, 0, 0), 5, lineType=8, shift=1)
# def line(img, pt1, pt2, color, thickness=None, lineType=None, shift=None)
# img : 要画的线所在的图像
# pt1 : 直线起点
# pt2 : 直线终点
# color : 线条颜色 BGR
# thickness : 线条宽度
# lineType : 8 -- 8-connected line 8邻连接线
# 4 -- 4-connected line 4邻连接线
# CV_AA 反锯齿连接线 (采用了高斯滤波)
# shift : 坐标点小数点位数(即坐标点的缩小倍数,0表示不缩小,1表示缩小10背
# 比如现在坐标是 起点(100, 100),终点(511,511) shift = 1 坐标就变成 起点(10.0, 10.0),终点(51.1, 51.1)
cv2.namedWindow('line')
cv2.imshow('line', img)
cv2.waitKey(10000) #显示 10000ms 即10s后消失
cv2.destroyAllWindows()
#关于linetype这个参数,可以用下面这段代码去体验不同值的不同效果
#
# lineType = cv2.LINE_8
# # lineType = cv2.LINE_4
# # lineType = cv2.LINE_AA
#
# img = np.zeros((420, 1000, 4), np.uint8)
# cv2.putText(
# img=img,
# text='XerCis',
# org=(0, 300),
# fontFace=cv2.FONT
python + opencv 第四节 绘图函数 绘制直线 绘制矩形
最新推荐文章于 2025-10-10 11:38:30 发布

最低0.47元/天 解锁文章
4956

被折叠的 条评论
为什么被折叠?



