OpenCV documentation index - OpenCV 文档索引
https://www.docs.opencv.org/

master (4.x)
https://www.docs.opencv.org/master/

3.4 (3.4.x)
https://www.docs.opencv.org/3.4/

2.4 (2.4.x)
https://www.docs.opencv.org/2.4/

1. 3.4 (3.4.x) -> Modules -> Image Processing -> Drawing Functions -> polylines()

1.1 Function Documentation - polylines()

void cv::polylines (InputOutputArray img,
InputArrayOfArrays pts,
bool isClosed,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0

Python

img = cv.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]]  )
#include <opencv2/imgproc.hpp>

Draws several polygonal curves.
绘制几条多边形曲线。

Parameters
img - Image.
pts - Array of polygonal curves.
isClosed - Flag indicating whether the drawn polylines are closed or not. If they are closed, the function draws a line from the last vertex of each curve to its first vertex.
color - Polyline color.
thickness - Thickness of the polyline edges.
lineType - Type of the line segments.
shift - Number of fractional bits in the vertex coordinates.

The function cv::polylines draws one or more polygonal curves.
函数 cv :polylines 绘制一条或多条多边形曲线。

To draw a polygon, first you need coordinates of vertices. Make those points into an array of shape ROWSx1x2 where ROWS are number of vertices and it should be of type int32. Here we draw a small polygon of with four vertices in yellow color.
画多边形,首先需要给出一组 (数组) 顶点的坐标,形式是 ROWSx1x2,ROWS 表示顶点的数量,它的类型是 int32。这里我们用黄色画一个小的四边形。

If third argument is False, you will get a polylines joining all the points, not a closed shape.
如果第三个参数设为 False,只会得到顶点依次相连的图形 (首尾不连),而不会得到所有顶点封闭连接的图形。

cv2.polylines() can be used to draw multiple lines. Just create a list of all the lines you want to draw and pass it to the function. All lines will be drawn individually. It is more better and faster way to draw a group of lines than calling cv2.line() for each line.
cv2.polylines() 可以被用来同时画多条线,只需要同时创建多个线段,传入函数中,它将独立的画出所有线,这比重复为每条线调用 cv2.line() 更快更好。

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

2. 2.4.13 (2.4.x) -> core. The Core Functionality -> Drawing Functions -> polylines()

https://docs.opencv.org/2.4/index.html

2.1 Function Documentation - polylines()

Draws several polygonal curves.

C++:
void polylines(Mat& img, const Point** pts, const int* npts, int ncontours, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )C++:
void polylines(InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )Python:
cv2.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]]) → NoneC:
void cvPolyLine(CvArr* img, CvPoint** pts, const int* npts, int contours, int is_closed, CvScalar color, int thickness=1, int line_type=8, int shift=0 )Python:
cv.PolyLine(img, polys, is_closed, color, thickness=1, lineType=8, shift=0) → None
  • Parameters

img - Image.
pts - Array of polygonal curves.
npts - Array of polygon vertex counters.
ncontours - Number of curves.
isClosed - Flag indicating whether the drawn polylines are closed or not. If they are closed, the function draws a line from the last vertex of each curve to its first vertex.
color - Polyline color.
thickness - Thickness of the polyline edges.
lineType - Type of the line segments.
shift - Number of fractional bits in the vertex coordinates.
The function polylines draws one or more polygonal curves.

3. polygons and polylines

#!/usr/bin/python3
# -*- coding: utf-8 -*-"""
polylines()
Draws several polygonal curves.
"""# Import required packages
import numpy as np
import cv2# Dictionary containing some colors.
colors = {'blue': (255, 0, 0), 'green': (0, 255, 0), 'red': (0, 0, 255), 'yellow': (0, 255, 255),'magenta': (255, 0, 255), 'cyan': (255, 255, 0), 'white': (255, 255, 255), 'black': (0, 0, 0),'gray': (125, 125, 125), 'rand': np.random.randint(0, high=256, size=(3,)).tolist(),'dark_gray': (50, 50, 50), 'light_gray': (220, 220, 220)}image = np.zeros((512, 512, 3), np.uint8)
cv2.namedWindow("image_show")while (True):# We are going to draw several polylines."""polylines(img, pts, isClosed, color, thickness=None, lineType=None, shift=None)polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]]) -> img.   @brief Draws several polygonal curves...   @param img - Image..   @param pts - Array of polygonal curves..   @param isClosed - Flag indicating whether the drawn polylines are closed or not. If they are closed,.   the function draws a line from the last vertex of each curve to its first vertex..   @param color - Polyline color..   @param thickness - Thickness of the polyline edges..   @param lineType - Type of the line segments. See the line description..   @param shift - Number of fractional bits in the vertex coordinates...   The function polylines draws one or more polygonal curves."""# These points define a triangle:pts = np.array([[250, 5], [220, 80], [280, 80]], np.int32)# Reshape to shape (number_vertex, 1, 2)pts = pts.reshape((-1, 1, 2))# Print the shapes: this line is not necessary, only for visualization:print("shape of pts '{}'".format(pts.shape))# Draw this polygon with True option:cv2.polylines(image, [pts], True, colors['green'], 3)# These points define a triangle:pts = np.array([[250, 105], [220, 180], [280, 180]], np.int32)# Reshape to shape (number_vertex, 1, 2)pts = pts.reshape((-1, 1, 2))# Print the shapes:print("shape of pts '{}'".format(pts.shape))# Draw this polygon with False option:cv2.polylines(image, [pts], False, colors['green'], 3)# These points define a pentagon:pts = np.array([[20, 90], [60, 60], [100, 90], [80, 130], [40, 130]], np.int32)# Reshape to shape (number_vertex, 1, 2)pts = pts.reshape((-1, 1, 2))# Print the shapes:print("shape of pts '{}'".format(pts.shape))# Draw this polygon with True option:cv2.polylines(image, [pts], True, colors['blue'], 3)# These points define a pentagon:pts = np.array([[20, 180], [60, 150], [100, 180], [80, 220], [40, 220]], np.int32)# Reshape to shape (number_vertex, 1, 2)pts = pts.reshape((-1, 1, 2))# Print the shapes:print("shape of pts '{}'".format(pts.shape))# Draw this polygon with False option:cv2.polylines(image, [pts], False, colors['blue'], 3)# These points define a rectangle:pts = np.array([[150, 100], [200, 100], [200, 150], [150, 150]], np.int32)# Reshape to shape (number_vertex, 1, 2)pts = pts.reshape((-1, 1, 2))# Print the shapes:print("shape of pts '{}'".format(pts.shape))# Draw this polygon with False option:cv2.polylines(image, [pts], True, colors['yellow'], 3)# These points define a rectangle:pts = np.array([[150, 200], [200, 200], [200, 250], [150, 250]], np.int32)# Reshape to shape (number_vertex, 1, 2)pts = pts.reshape((-1, 1, 2))# Print the shapes:print("shape of pts '{}'".format(pts.shape))# Draw this polygon with False option:cv2.polylines(image, [pts], False, colors['yellow'], 3)cv2.imshow("image_show", image)k = cv2.waitKey(200) & 0xFFif 27 == k:breakcv2.destroyAllWindows()

绘制 polygons and polylines:OpenCV版本相关推荐

  1. 绘制 polygons and polylines(shapefile读写):pyshp (shapefile)版本

    注意:安装命令:pip install pyshp,使用:import shapefile Before doing anything you must import the library. > ...

  2. vs2010利用属性表自动配置OpenCV(win7的64位系统,opencv版本是2.4.10)

    每建一个工程都要手动配置一遍Opencv,太麻烦了.vs可以使用属性表配置属性,研究了一下,我的电脑配置是win7的64位系统,opencv版本是2.4.10,属性表(opencv2410.props ...

  3. 因OpenCV版本不一致所引发的报错

    目录 一 因OpenCV版本不一致所引发的报错 注:原创不易,转载请务必注明原作者和出处,感谢支持! 一 因OpenCV版本不一致所引发的报错 今天遇到了一个很有意思的报错. 事情是这样的, 在编译& ...

  4. ubuntu1804查看opencv版本

    做个备忘,ubuntu1804系统查看opencv版本 均在终端下进行 方法1 pkg-config --modversion opencv 方法2 python import cv2 # 查看版本 ...

  5. surf和sift算法被申请专利后部分opencv版本无法使用后的安装pycharm+opencv使用surf和sift算法教程

    安装pycharm+opencv教程使用surf和sift算法 surf和sift算法在pycharm中的问题 安装过程 使用的软件版本 安装步骤 一.pycharm的安装 二.尝试打开pycharm ...

  6. Pycharm项目中更改python版本以及opencv版本

    原来我使用的项目版本是anaconda下安装了python3.9和opencv4.6 最近在项目中需要用到openc3.4.2.16的版本,同时为了适配这个opencv的版本需要将python解释器的 ...

  7. ROS学习:cv_bridge与opencv版本冲突三种解决方案

    cv_bridge与opencv版本冲突三种解决方案 1 问题描述: 2 解决方案: 2.1 不使用cv_bridge包 2.2 令cv_bridge使用opencv版本切换为自己工程所使用的版本 2 ...

  8. 查看Eigen、CMake、ceres、opencv版本

    文章目录 查看Eigen版本 查看CMake版本 查看ceres版本 查看OPencv版本 查看Eigen版本 找到eigen本地目录下的Macros.h头文件查看对应的版本. 执行如下命令: sud ...

  9. Linux查看opencv 版本

    命令如下: [plain] view plaincopyprint? pkg-config --modversion opencv 库文件一般放在: /usr/local/lib (PS,系统装的Op ...

最新文章

  1. Java学习笔记25
  2. matlab与音频处理
  3. 夜间模式html,夜间模式.html
  4. ros(5)service client实现
  5. Mac下解决editcap等wireshark配套工具not found
  6. 应用挂载beegfs指定目录_BeeGFS源码分析1-元数据服务概要分析
  7. allegro 16.6 空心焊盘的制作
  8. 阿里云虚拟主机的使用,附幸运券领取
  9. 54.Linux/Unix 系统编程手册(下) -- POSIX 共享内存
  10. 详解MySQL中EXPLAIN解释命令(转)
  11. android 如何自定义桌面,安卓手机桌面设置教程 个性化你的桌面
  12. 职位搜索引擎职友集开放招聘信息协议
  13. NB-IOT相关的术语 SGW、PGW、LTE、RRC、E-UTRAN、EPC
  14. 分频器——秒分频、三分频、五分频、任意分频和偶数分频
  15. 计算机微机维修工四级理论知识试卷,计算机维修工中级理论知识试卷2
  16. python+django+layUI+MySQL+TSC打印机搭建4G设备管理平台项目(二)——过程中的难点记录
  17. Android-茫茫9个月求职路,终于拿满意offer,项目实践
  18. unique中译_unique 是什么意思_unique 的翻译_音标_读音_用法_例句_爱词霸在线词典...
  19. WordPress 元老 Alex King 逝世
  20. 互动机顶盒与普通机顶盒比较

热门文章

  1. 嵌入式UWB定位测距设备开发实战(4)硬件之元器件选型
  2. 大数据和人工智能AI的联系和区别
  3. 匹配,为什么要“共轭”
  4. 2005年10月--至今,开发过的项目
  5. anbox 使用情况_如何在Linux PC上启动并运行Anbox?
  6. 网络不断电系统服务器ip,IP网络控制主机 T-7700N
  7. postgreSQL数据库的监控及数据维护
  8. (原创)[短小精悍系列]RGB(RGI/RGV)颜色明度(亮度)计算公式 (又称灰度公式,彩色照片转黑白照片时能派上用场)
  9. excel合并sheet表格
  10. i3cpu驱动xp_Intel英特尔 Core i3/Core i5/Core i7系列CPU显示驱动 14.46.9.5394版 For XP-64