线条、椭圆、矩形、圆、多边形

线条line()void cv::line   (   InputOutputArray    img,Point   pt1,Point   pt2,const Scalar &  color,int     thickness = 1,int     lineType = LINE_8,int     shift = 0 ) 椭圆ellipse() void cv::ellipse    (   InputOutputArray    img,Point   center,Size    axes,double  angle,double  startAngle,double  endAngle,const Scalar &  color,int     thickness = 1,int     lineType = LINE_8,int     shift = 0 ) 矩形rectangle() void cv::rectangle  (   InputOutputArray    img,Point   pt1,Point   pt2,const Scalar &  color,int     thickness = 1,int     lineType = LINE_8,int     shift = 0 ) 圆circle()void cv::circle (   InputOutputArray    img,Point   center,int     radius,const Scalar &  color,int     thickness = 1,int     lineType = LINE_8,int     shift = 0 ) 多边形fillPoly()void cv::fillPoly   (   Mat &   img,const Point **  pts,const int *     npts,int     ncontours,const Scalar &  color,int     lineType = LINE_8,int     shift = 0,Point   offset = Point() )  

代码示例

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>#define w 400using namespace cv;void MyEllipse(Mat img, double angle);
void MyFilledCircle(Mat img, Point center);
void MyPolygon(Mat img);
void MyRect(Mat img);
void MyLine(Mat img, Point start, Point end);int main(void)
{Mat atom_image = Mat::zeros(w, w, CV_8UC3);Mat rook_image = Mat::zeros(w, w, CV_8UC3);MyEllipse(atom_image, 90);                                          // 椭圆MyEllipse(atom_image, 0);MyEllipse(atom_image, 45);MyEllipse(atom_image, -45);MyFilledCircle(atom_image, Point(w / 2, w / 2));                    // 圆MyPolygon(rook_image);                                              // 多边形MyRect(rook_image);                                                 // 矩形MyLine(rook_image, Point(0, 15 * w / 16), Point(w, 15 * w / 16));   // 线条MyLine(rook_image, Point(w / 4, 7 * w / 8), Point(w / 4, w));MyLine(rook_image, Point(w / 2, 7 * w / 8), Point(w / 2, w));MyLine(rook_image, Point(3 * w / 4, 7 * w / 8), Point(3 * w / 4, w));char atom_window[] = "Drawing 1:Atom";char rook_window[] = "Drawing 2:Rook";imshow(atom_window, atom_image);moveWindow(atom_window, 0, 200);imshow(rook_window, rook_image);moveWindow(rook_window, w, 200);waitKey(0);return(0);
}void MyEllipse(Mat img, double angle)
{int thickness = 2;int lineType = 8;ellipse(img,Point(w / 2, w / 2),Size(w / 4, w / 16),angle,0,360,Scalar(255, 0, 0),thickness,lineType);
}void MyFilledCircle(Mat img, Point center)
{circle(img,center,w / 32,Scalar(0, 0, 255),FILLED,LINE_8);
}void MyPolygon(Mat img)
{int lineType = LINE_8;Point rook_points[1][20];rook_points[0][0] = Point(w / 4, 7 * w / 8);rook_points[0][1] = Point(3 * w / 4, 7 * w / 8);rook_points[0][2] = Point(3 * w / 4, 13 * w / 16);rook_points[0][3] = Point(11 * w / 16, 13 * w / 16);rook_points[0][4] = Point(19 * w / 32, 3 * w / 8);rook_points[0][5] = Point(3 * w / 4, 3 * w / 8);rook_points[0][6] = Point(3 * w / 4, w / 8);rook_points[0][7] = Point(26 * w / 40, w / 8);rook_points[0][8] = Point(26 * w / 40, w / 4);rook_points[0][9] = Point(22 * w / 40, w / 4);rook_points[0][10] = Point(22 * w / 40, w / 8);rook_points[0][11] = Point(18 * w / 40, w / 8);rook_points[0][12] = Point(18 * w / 40, w / 4);rook_points[0][13] = Point(14 * w / 40, w / 4);rook_points[0][14] = Point(14 * w / 40, w / 8);rook_points[0][15] = Point(w / 4, w / 8);rook_points[0][16] = Point(w / 4, 3 * w / 8);rook_points[0][17] = Point(13 * w / 32, 3 * w / 8);rook_points[0][18] = Point(5 * w / 16, 13 * w / 16);rook_points[0][19] = Point(w / 4, 13 * w / 16);const Point* ppt[1] = { rook_points[0] };int npt[] = { 20 };fillPoly(img,ppt,npt,1,Scalar(255, 255, 255),lineType);
}void MyRect(Mat img)
{rectangle(img,Point(0, 7 * w / 8),Point(w, w),Scalar(0, 255, 255),FILLED,LINE_8);
}void MyLine(Mat img, Point start, Point end)
{int thickness = 2;int lineType = LINE_8;line(img,start,end,Scalar(0, 0, 0),thickness,lineType);
}

运行结果


【OpenCV】绘制简单图形相关推荐

  1. python opencv 绘制简单图形

    09-python opencv 绘制简单图形 09-python opencv 绘制简单图形 概述 实现过程 引用与创建空图 绘制直线 绘制矩形 绘制圆 绘制椭圆 添加文字 显示图像 源代码 运行结 ...

  2. [Qt教程] 第11篇 2D绘图(一)绘制简单图形

    [Qt教程] 第11篇 2D绘图(一)绘制简单图形 楼主  发表于 2013-4-23 12:52:35 | 查看: 1398| 回复: 5 绘制简单图形 版权声明 该文章原创于Qter开源社区,作者 ...

  3. java 绘制长方形_Java入门:绘制简单图形

    在上一节,我们学习了如何使用swing和awt工具创建一个空的窗口,本节学习如何绘制简单图形. 基本绘图介绍 Java中绘制基本图形,可以使用Java类库中的Graphics类,此类位于java.aw ...

  4. Python之Turtle库绘制简单图形

    Python之Turtle库绘制简单图形 来绘制正方形.三角形.五边形.五角形 import turtle #引入turtle库pen=turtle.Turtle() #创建turtle类型的画笔 # ...

  5. plotly绘制简单图形4--饼形图

    plotly绘制简单图形<1>--散点图折线图 plotly绘制简单图形<2>--条形图 plotly绘制简单图形<3>--设置按钮 本次说一下饼形图: 目录 1. ...

  6. plotly绘制简单图形5--饼形图附加

    plotly绘制简单图形<4>--饼形图里说了饼形图的基本设置, 这里补充一个怎样设置两个饼图的方法(数据是爬取京东手机和电脑价格数据分析结果) import plotly.plotly ...

  7. python的turtle怎么画曲线_利用 turtle库绘制简单图形

    turtle库是python的基础绘图库,这个库被介绍为一个最常用的用来介绍编程知识的方法库,其主要是用于程序设计入门,是标准库之一,利用turtle可以制作很多复杂的绘图. turtle名称含义为& ...

  8. python matplotlib绘制函数图形_【总结篇】Python matplotlib之使用统计函数绘制简单图形...

    写在前面 作者注:我在这里只总结函数的功能及其用法,程序实例参考链接:link 我们用下面的语句来导入matplotlib库: 1import matplotlib.pyplot as plt 绘制简 ...

  9. Android openGl开发详解(一)——绘制简单图形

    1. What? openGl是什么?openGl ES又是什么? 2. How? Android中的openGL 如何使用? 3. GlSurfaceView是什么? GLSurfaceView的作 ...

  10. Java入门:绘制简单图形

    在上一节,我们学习了如何使用swing和awt工具创建一个空的窗口,本节学习如何绘制简单图形. 基本绘图介绍 Java中绘制基本图形,可以使用Java类库中的Graphics类,此类位于java.aw ...

最新文章

  1. shell (7)if 表达式
  2. pytorch dropout_PyTorch初探MNIST数据集
  3. 计算机与数学专业的就业前景,2019数学与应用数学专业就业前景和就业方向分析...
  4. 大数据治理平台有哪些价值
  5. c++ 宏 stdin 和 STDIN_FILENO 区别
  6. Windows10桌面美化——打造简洁高效美观桌面
  7. PHP 解压 ZIP 文件到指定文件夹
  8. python知道章节答案_智慧树知道Python数据分析与数据可视化答案,章节期末教程考试网课答案...
  9. 实用工具证件照制作微信小程序源码
  10. 实力肯定!Coremail邮件网关荣获金融信创优秀解决方案奖
  11. cos三次方积分_cos三次方的定积分
  12. TCP/IP五层模型介绍
  13. 【epoll】epoll使用详解(精髓)--研读和修正
  14. 为何要重建索引 index
  15. 微信公众号自动回复机器人
  16. SQL命令讲解(二)
  17. 缓冲进度条或加载进度条
  18. 歌曲《幽兰操》,演唱:宁静
  19. 天津室内设计培训班:30岁兼职室内设计月薪过万,我是怎么做到的?
  20. pip3 install pymysql

热门文章

  1. 开方计算与浮点数的问题
  2. 《南溪的目标检测学习笔记》——训练PyTorch模型遇到显存不足的情况怎么办(“OOM: CUDA out of memory“)
  3. Intellij IDEA基本配置
  4. 理解Java多线程高并发Executor框架的使用
  5. ASP.NET MVC 1.0 学习笔记(随时更新)
  6. 使用盒子模型仿照优酷的页面片段
  7. zend studio怎么连接mysql?
  8. JS实现图片翻书效果
  9. 前端基于Canvas生成等值面的方案
  10. [Windows] 程序生成出现语法错误: 意外的令牌“标识符”,预期的令牌为“类型说明符”...