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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。