线段:line 函数

CV_EXPORTS_W void line(CV_IN_OUT Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineT ype=8, int shift=0);
  • img: 要绘制线段的图像。
  • pt1: 线段的起点。
  • pt2: 线段的终点。
  • color: 线段的颜色,通过一个Scalar对象定义。
  • thickness: 线条的宽度。
  • lineType: 线段的类型。可以取值8, 4, 和CV_AA, 分别代表8邻接连接线,4邻接连接线和反锯齿连接线。默认值为8邻接。为了获得更好地效果可以选用CV_AA(采用了高斯滤波)。
  • shift: 坐标点小数点位数。

椭圆:ellipse 函数

CV_EXPORTS_W void ellipse(CV_IN_OUT Mat& img, Point center, Size axes,double angle, double startAngle, double endAngle, const Scalar& color, int thickness=1,int lineType=8, int shift=0);
  • img: 要绘制椭圆的图像。
  • center: 椭圆中心点坐标。
  • axes: 椭圆位于该Size决定的矩形内。(即定义长轴和短轴)。
  • angle: 椭圆旋转角度。
  • startAngle: 椭圆开始绘制时角度。
  • endAngle: 椭圆绘制结束时角度。(若绘制一个完整的椭圆,则startAngle=0, endAngle = 360)。
  • color: 椭圆的颜色。
  • thickness: 绘制椭圆线粗。负数表示全部填充。
  • lineType、shift:同上。

矩形:rectangle 函数

CV_EXPORTS_W void rectangle(CV_IN_OUT Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0);
  • pt1: 矩形的左上角坐标。
  • pt2: 矩阵的右下角坐标。
  • 其余同上。

圆:circle 函数

CV_EXPORTS_W void circle(CV_IN_OUT Mat& img, Point center, int radius, const Scalar& color, int thickness=1, int lineType=8, int shift=0);
  • center: 圆心坐标。
  • radius: 半径。
  • 其余同上。

填充多边形:fillPoly 函数

CV_EXPORTS void fillPoly(Mat& img, const Point** pts,const int* npts, int ncontours, const Scalar& color, int lineType=8, int shift=0, Point offset=Point() );
  • pts: 多边形定点集。
  • npts: 多边形的顶点数目。
  • ncontours: 要绘制多边形的数量。
  • offset: 所有点轮廓的可选偏移。
  • 其余同上。

显示文字:PutText 函数

void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false )
  • img – 显示文字所在图像.
  • text – 待显示的文字.
  • org – 文字在图像中的左下角 坐标.
  • font – 字体结构体.
  • fontFace – 字体类型, 可选择字体:

FONT_HERSHEY_SIMPLEX, FONT_HERSHEY_PLAIN,

FONT_HERSHEY_DUPLEX, FONT_HERSHEY_COMPLEX,

FONT_HERSHEY_TRIPLEX, FONT_HERSHEY_COMPLEX_SMALL,

FONT_HERSHEY_SCRIPT_SIMPLEX, or FONT_HERSHEY_SCRIPT_COMPLEX,

以上所有类型都可以配合FONT_HERSHEY_ITALIC使用,产生斜体效果。

  • fontScale – 字体大小,该值和字体内置大小相乘得到字体大小
  • color – 文本颜色
  • thickness – 写字的线的粗细
  • lineType – 线型.
  • bottomLeftOrigin – true, 图像数据原点在左下角。否则, 图像数据原点在左上角.

示例

#include<core.hpp>
#include<highgui.hpp>
#include<imgproc.hpp>
using namespace cv; #define WINDOW_NAME1 "[绘制图1]" //为窗口标题定义的宏
#define WINDOW_NAME2 "[绘制图2]" //为窗口标题定义的宏
#define WINDOW_WIDTH 600 //定义窗口大小的宏 //绘制不同角度。相同尺寸的椭圆
void DrawEllipse(Mat img, double angle)
{
int thickness = 2;
int lineType = 8;
ellipse(img, Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2),
Size(WINDOW_WIDTH / 4, WINDOW_WIDTH / 16), angle,
0, 360, Scalar(255, 129, 0), thickness, lineType);
} //绘制实心圆
void DrawFilledCircle(Mat img, Point center)
{
int thickness = -1; //线粗
int lineType = 8;
circle(img, center, WINDOW_WIDTH / 32, Scalar(0, 0, 255),
thickness, lineType);
} //实现凹多边形绘制
void DrawPolygon(Mat img)
{
int lineType = 8; //创建一些点
Point rootPoints[1][20];
rootPoints[0][0] = Point(WINDOW_WIDTH / 4, 7 * WINDOW_WIDTH / 8);
rootPoints[0][1] = Point(3 * WINDOW_WIDTH / 4, 7 * WINDOW_WIDTH / 8);
rootPoints[0][2] = Point(3 * WINDOW_WIDTH / 4, 13 * WINDOW_WIDTH / 16);
rootPoints[0][3] = Point(11 * WINDOW_WIDTH / 16, 13 * WINDOW_WIDTH / 16);
rootPoints[0][4] = Point(19 * WINDOW_WIDTH / 32, 3 * WINDOW_WIDTH / 8);
rootPoints[0][5] = Point(3 * WINDOW_WIDTH / 4, 3 * WINDOW_WIDTH / 8);
rootPoints[0][6] = Point(3 * WINDOW_WIDTH / 4, WINDOW_WIDTH / 8);
rootPoints[0][7] = Point(26 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8);
rootPoints[0][8] = Point(26 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4);
rootPoints[0][9] = Point(22 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4);
rootPoints[0][10] = Point(22 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8);
rootPoints[0][11] = Point(18 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8);
rootPoints[0][12] = Point(18 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4);
rootPoints[0][13] = Point(14 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4);
rootPoints[0][14] = Point(14 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8);
rootPoints[0][15] = Point(WINDOW_WIDTH / 4, WINDOW_WIDTH / 8);
rootPoints[0][16] = Point(WINDOW_WIDTH / 4, 3 * WINDOW_WIDTH / 8);
rootPoints[0][17] = Point(13 * WINDOW_WIDTH / 32, 3 * WINDOW_WIDTH / 8);
rootPoints[0][18] = Point(5 * WINDOW_WIDTH / 16, 13 * WINDOW_WIDTH / 16);
rootPoints[0][19] = Point(WINDOW_WIDTH / 4, 13 * WINDOW_WIDTH / 16);
const Point* ppt[1] = { rootPoints[0] };
int npt[] = { 20 };
fillPoly(img, ppt, npt, 1, Scalar(255, 255, 255), lineType);
} // 绘制线
void DrawLine(Mat img, Point start, Point end)
{
int thickness = 2;
int lineType = 8;
line(img, start, end, Scalar(0, 0, 0), thickness, lineType);
} int main()
{
//创建空白的Mat图像
Mat atomImage = Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3);
Mat rookImage = Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3); //----------- 绘制化学中原子的示例图-----------
//1.先绘制出椭圆
DrawEllipse(atomImage, 90);
DrawEllipse(atomImage, 0);
DrawEllipse(atomImage, 45);
DrawEllipse(atomImage, -45); //2.再绘制出圆心
DrawFilledCircle(atomImage, Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2)); //----------- 绘制组合图形----------------
//1.线绘制出多边形
DrawPolygon(rookImage); //2.绘制矩形
rectangle(rookImage, Point(0, 7 * WINDOW_WIDTH),
Point(WINDOW_WIDTH, WINDOW_WIDTH), Scalar(0, 255, 255), -1, 8); //2.绘制一些线段
DrawLine(rookImage, Point(0, 15 * WINDOW_WIDTH / 16),
Point(WINDOW_WIDTH, 15 * WINDOW_WIDTH / 16));
DrawLine(rookImage, Point(WINDOW_WIDTH / 4, 7 * WINDOW_WIDTH / 8),
Point(WINDOW_WIDTH / 4, WINDOW_WIDTH));
DrawLine(rookImage, Point(WINDOW_WIDTH / 2, 7 * WINDOW_WIDTH / 8),
Point(WINDOW_WIDTH / 2, WINDOW_WIDTH));
DrawLine(rookImage, Point(3 * WINDOW_WIDTH / 4, 7 * WINDOW_WIDTH / 8),
Point(3 * WINDOW_WIDTH / 4, WINDOW_WIDTH)); //3.显示绘制出的图像
imshow(WINDOW_NAME1, atomImage);
moveWindow(WINDOW_NAME1, 0, 200);
imshow(WINDOW_NAME2, rookImage);
moveWindow(WINDOW_NAME2, WINDOW_WIDTH, 200); waitKey(0);
return 0;
}

OpenCV基本绘图函数的更多相关文章

  1. opencv 基本绘图函数

    opencv 常用的数据结构和函数 颜色空间转换函数 cvtColor 函数 cvtColor 函数是opencv 中的颜色空间转换函数.可以实现rgb向hsv hsi等颜色空间的转换,也可以转换成灰 ...

  2. opencv-python教程学习系列4-opencv绘图函数

    前言 opencv-python教程学习系列记录学习python-opencv过程的点滴,本文主要介绍opencv绘图函数,坚持学习,共同进步. 系列教程参照OpenCV-Python中文教程: 系统 ...

  3. OpenCV中的绘图函数-OpenCV步步精深

    OpenCV 中的绘图函数 画线 首先要为画的线创造出环境,就要生成一个空的黑底图像 img=np.zeros((512,512,3), np.uint8) 这是黑色的底,我们的画布,我把窗口名叫做i ...

  4. opencv学习之路(4)、Mat类介绍,基本绘图函数

    一.Mat类创建 Mat img;//创建无初始化矩阵 Mat img1(,,CV_8UC1);//200行,100列(长200,宽100) Mat img2(Size(,),CV_8UC3,Scal ...

  5. OpenCV绘图函数

    OpenCV几个绘图函数 矩形 rectangle(Mat& img,Point pt1, Point pt2, const Scalar&color, int thickness=1 ...

  6. 5、opencv中的绘图函数

    1.目标 a.学习使用 OpenCV 绘制不同几何图形 b. 你将会学习到这些函数: cv2.line(), cv2.circle(), cv2.rectangle(),cv2.ellipse(),c ...

  7. OpenCV中的绘图函数

    OpenCV可以用来绘制不同的集合图形,包括直线,矩形,圆,椭圆,多边形以及在图片上添加文字.用到的绘图函数包括 cv2.line(),cv2.circle(),cv2.rectangle() ,cv ...

  8. Opencv笔记(四)——绘图函数

    常用的绘图函数有: cv2.line()       cv2.circle()        cv2.rectangle()      cv2.ellipse()       cv2.putText( ...

  9. OpenCV3入门(三)基本绘图函数

    1.函数原型 /** @brief Draws a line segment connecting two points.*/ CV_EXPORTS_W void line(InputOutputAr ...

随机推荐

  1. (三)(2)wait/notify实现生产者-消费者模型,join方法

    生产者,消费者模型 举个例子来说明,厨师,服务员,厨师做菜,服务员上菜,如果厨师没有做好菜,那么服务员就无法上菜,厨师做好了菜,然后通知服务员消费(上菜).在这个过程之中,厨师扮演的就是生产者,服务员 ...

  2. throw throws区别

    1.throws是在方法上对一个方法进行声明,而不进行处理,向上传,谁调用谁处理: 格式: 权限修饰符 返回值类型 方法名(参数列表) throws Exception1,Exception2...{ ...

  3. Mysql设置创建时间字段和更新时间字段自动获取时间,填充时间

    1.引言在实际开发中,每条数据的创建时间和修改时间,尽量不需要应用程序去记录,而由数据库获取当前时间自动记录创建时间,获取当前时间自动记录修改时间. 2.创建语句(1)–添加CreateTime 设置 ...

  4. Nginx总结(八)Nginx服务器的日志管理及配置

    前面讲了如何配置Nginx虚拟主机,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要 ...

  5. bat常用符合和for语句等

    一.开头 @echo off(默认是echo on)@echo off执行以后,后面所有的命令均不显示,包括本条命令 二.特殊符号 1. | 命令管道符,echo Y|rd /s c:\abc,通过管 ...

  6. KNN和K-Means算法

    一.KNN算法 1.KNN算法介绍 https://wizardforcel.gitbooks.io/dm-algo-top10/content/knn.html 2.KNN算法例子 import n ...

  7. PHP 安装扩展步骤

    一般来说php安装扩展需要几下几个步骤   1.下载扩展包    比如  pdo_mysql.tar.gz  (如果不想下载,可以到php安装目录,(类似php-5.3.3/ext/)的ext文件中找 ...

  8. AJAX传输图片文件

    AJAX传输 例:const xhr = new XMLHttpRequest(); // 此方法因为状态改变被调用多次,实测执行三次(1->2->4) xhr.onreadystatec ...

  9. 使用requests、re、BeautifulSoup、线程池爬取携程酒店信息并保存到Excel中

    import requests import json import re import csv import threadpool import time, random from bs4 impo ...

  10. 关键两步+6个要点,让Windows应用程序享有K8S的绝佳优势

    本文来自Rancher Labs 前  言 实际上,没有一个迁移路径能够适用于将所有传统应用程序迁移到云.这些应用程序通常在物理机.虚拟机或本地.虽然一般情况下是重新设计应用程序架构以适用云原生服务, ...