OpenCV是用于计算机视觉,机器学习和图像处理的巨大开源库,现在它在实时操作中起着重要作用,这在当今的系统中非常重要。通过使用它,可以处理图像和视频来识别物体,面孔,或人类的连笔迹。当它与不同的库,如Numpuy集成,蟒能够处理的OpenCV阵列结构进行分析。
注意:欲了解更多信息,请参阅OpenCV的Python指南
cv2.polylines()
cv2.polylines()方法用于绘制任何图像上的多边形。
用法: cv2.polylines(image, [pts], isClosed, color, thickness)
参数:
image:这是上圆要绘制的图像。
pts:多边形曲行数组。
npts:多边形顶点计数器阵列。
ncontours:曲行数量。
isClosed:指示绘制的折线是否闭合的标志。如果它们是闭合的,则该函数从每条曲线的最后一个顶点到其第一个顶点绘制一条线
顶点。
color:这是折线的颜色来绘制。对于BGR,我们传递一个元组。
thickness:它是折线边的厚度。
返回值:它返回一个图像。
用于以下所有示例的图像:
用于以下所有示例的图像:
范例1:
# Python program to explain
# cv2.polylines() method
import cv2
import numpy as np
# path
path = gfg.jpeg'
# Reading an image in default
# mode
image = cv2.imread(path)
# Window name in which image is
# displayed
window_name = 'Image'
# Polygon corner points coordinates
pts = np.array([[25, 70], [25, 160],
[110, 200], [200, 160],
[200, 70], [110, 20]],
np.int32)
pts = pts.reshape((-1, 1, 2))
isClosed = True
# Blue color in BGR
color = (255, 0, 0)
# Line thickness of 2 px
thickness = 2
# Using cv2.polylines() method
# Draw a Blue polygon with
# thickness of 1 px
image = cv2.polylines(image, [pts],
isClosed, color, thickness)
# Displaying the image
while(1):
cv2.imshow('image', image)
if cv2.waitKey(20) & 0xFF == 27:
break
cv2.destroyAllWindows()
输出:
范例2:
# Python program to explain
# cv2.polylines() method
import cv2
import numpy as np
# path
path = r'gfg.jpeg'
# Reading an image in default
# mode
image = cv2.imread(path)
# Window name in which image is
# displayed
window_name = 'Image'
# Polygon corner points coordinates
pts = np.array([[25, 70], [25, 145],
[75, 190], [150, 190],
[200, 145], [200, 70],
[150, 25], [75, 25]],
np.int32)
pts = pts.reshape((-1, 1, 2))
isClosed = True
# Green color in BGR
color = (0, 255, 0)
# Line thickness of 8 px
thickness = 8
# Using cv2.polylines() method
# Draw a Green polygon with
# thickness of 1 px
image = cv2.polylines(image, [pts],
isClosed, color,
thickness)
# Displaying the image
while(1):
cv2.imshow('image', image)
if cv2.waitKey(20) & 0xFF == 27:
break
cv2.destroyAllWindows()
输出:
相关用法
- Python OpenCV cv2.imread()用法及代码示例
- Python OpenCV cv2.imshow()用法及代码示例
- Python OpenCV cv2.imwrite()用法及代码示例
- Python OpenCV cv2.line()用法及代码示例
- Python OpenCV cv2.rectangle()用法及代码示例
- Python OpenCV cv2.circle()用法及代码示例
- Python OpenCV cv2.putText()用法及代码示例
- Python OpenCV cv2.ellipse()用法及代码示例
- Python OpenCV cv2.cvtColor()用法及代码示例
- Python OpenCV cv2.copyMakeBorder()用法及代码示例
- Python OpenCV cv2.arrowedLine()用法及代码示例
- Python OpenCV cv2.blur()用法及代码示例
- Python OpenCV cv2.erode()用法及代码示例
注:本文由纯净天空筛选整理自sourabhpanday2大神的英文原创作品 Python OpenCV – cv2.polylines() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。