如何推广网站,西园寺れお,冰心笺
polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]])
img
上画若干多边形
img
:要在上面画多边形的图像
pts
:包含多边形上点的数组
isClosed
:标志,决定所绘制的多边形是否闭合。若为 True
,则画若干个闭合多边形;若为 False
,则画一条连接所有点的折线
color
:多边形颜色
thickness
:多边形线的粗细
lineType
:多边形线的类型
shift
:坐标精确到小数点后第几位
img
:画完多边形的输入图像
# 导入 OpenCV import cv2 as cv import numpy as np import random # 读取图像 imgBgr = cv.imread(r'/home/work/0/OpenCV/0/img/Ta152.jpg') print('\nimgBgr.shape:', imgBgr.shape) # (768, 1024, 3) # 随机获取多边形坐标点列表 numPt = 5 # 每个多边形上坐标点的个数 listPt = [] for j in range(numPt): x = random.randrange(imgBgr.shape[1]) y = random.randrange(imgBgr.shape[0]) listPt.append([x, y]) # 多边形坐标点列表格式转换 arrPt = np.array(listPt, np.int32).reshape((-1, 1, 2)) # 画多边形 imgRet = cv.polylines(imgBgr, [arrPt], True, (0, 255, 0), 3) # 比较输入图像和返回图像的内存地址 print('\nid(imgBgr) == id(imgRet):', id(imgBgr) == id(imgRet)) # True # 显示图像 cv.imshow('imgBgr', imgBgr) idKey = cv.waitKey(0) if idKey == '27': # 27 为 ESC 键对应的 ASCII 码 cv.destroyAllWindows()
pts
参数外面要用 []
括起来
pts
参数中坐标的顺序为 (x, y)
本文地址:https://blog.csdn.net/zhanling1007/article/details/108865590
希望与广大网友互动?? 点此进行留言吧!
评论内容