OpenCV|OpenCV 基本图形绘制函数详解
- 用于绘制直线的line函数;
- 用于绘制椭圆的ellipse函数;
- 用于绘制矩形的rectangle函数;
- 用于绘制圆的circle函数;
- 用于绘制填充的多边形的fillPoly函数。
#include#include #include using namespace cv; using namespace std; #define WINDOW_WIDTH 600 // 定义窗口大小的宏#define WINDOW_NAME1 "原子图"//为窗口标题定义的宏 #define WINDOW_NAME2 "多边形图以及画线"//为窗口标题定义的宏 /***绘制椭圆***/void DrawEllipse(Mat img, double angle){int thickness = 2; //线宽int lineType = 8; // 线性,8 代表联通线性ellipse(img,Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2),Size(WINDOW_WIDTH / 4, WINDOW_WIDTH / 16),angle, // 角度,0~360 度0,360,Scalar(255, 129, 0),thickness,lineType); }/*绘制实心圆*/void DrawFilledCircle(Mat img, Point center)int thickness = -1; //线粗-1,代表实心circle(img,center,WINDOW_WIDTH / 32,Scalar(0, 0, 255),/*凹多边形绘制*/void DrawPolygon(Mat img)int lineType = 8; // 创建一些点Point rookPoints[1][20]; rookPoints[0][0] = Point(WINDOW_WIDTH / 4, 7 * WINDOW_WIDTH / 8); rookPoints[0][1] = Point(3 * WINDOW_WIDTH / 4, 7 * WINDOW_WIDTH / 8); rookPoints[0][2] = Point(3 * WINDOW_WIDTH / 4, 13 * WINDOW_WIDTH / 16); rookPoints[0][3] = Point(11 * WINDOW_WIDTH / 16, 13 * WINDOW_WIDTH / 16); rookPoints[0][4] = Point(19 * WINDOW_WIDTH / 32, 3 * WINDOW_WIDTH / 8); rookPoints[0][5] = Point(3 * WINDOW_WIDTH / 4, 3 * WINDOW_WIDTH / 8); rookPoints[0][6] = Point(3 * WINDOW_WIDTH / 4, WINDOW_WIDTH / 8); rookPoints[0][7] = Point(26 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8); rookPoints[0][8] = Point(26 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4); rookPoints[0][9] = Point(22 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4); rookPoints[0][10] = Point(22 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8); rookPoints[0][11] = Point(18 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8); rookPoints[0][12] = Point(18 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4); rookPoints[0][13] = Point(14 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 4); rookPoints[0][14] = Point(14 * WINDOW_WIDTH / 40, WINDOW_WIDTH / 8); rookPoints[0][15] = Point(WINDOW_WIDTH / 4, WINDOW_WIDTH / 8); rookPoints[0][16] = Point(WINDOW_WIDTH / 4, 3 * WINDOW_WIDTH / 8); rookPoints[0][17] = Point(13 * WINDOW_WIDTH / 32, 3 * WINDOW_WIDTH / 8); rookPoints[0][18] = Point(5 * WINDOW_WIDTH / 16, 13 * WINDOW_WIDTH / 16); rookPoints[0][19] = Point(WINDOW_WIDTH / 4, 13 * WINDOW_WIDTH / 16); const Point* ppt[1] = { rookPoints[0] }; // 多边形定点集int npt[] = { 20 }; // 多边形定点数目fillPoly(img, ppt, npt, 1, Scalar(255, 255, 255),// 多边形颜色:白色/*线绘制*/void DrawLine(Mat img, Point start, Point end)int thickness = 2; line(img,start,end,Scalar(0,0,0), // 黑色int main(int argc, char ** argv)Mat atomImage = Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3); Mat rookImage = Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3); // 椭圆绘制DrawEllipse(atomImage, 0); DrawEllipse(atomImage, 90); DrawEllipse(atomImage, 45); DrawEllipse(atomImage, -45); // 绘制圆心DrawFilledCircle(atomImage, Point(WINDOW_WIDTH / 2, WINDOW_WIDTH / 2)); // 绘制多边形DrawPolygon(rookImage); // 绘制矩形rectangle(rookImage,Point(0, 7 * WINDOW_WIDTH / 8),Point(WINDOW_WIDTH, WINDOW_WIDTH),Scalar(0, 255, 255),-1,8); // 绘制一些线段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|OpenCV 基本图形绘制函数详解】运行:
文章图片
参考:
《OpenCV3 编程入门》 毛星云 P104
到此这篇关于OpenCV 基本图形绘制函数的文章就介绍到这了,更多相关OpenCV 基本图形函数内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- 做一件事情的基本原理是什么()
- opencv|opencv C++模板匹配的简单实现
- Java|Java OpenCV图像处理之SIFT角点检测详解
- dubbo基本认识
- HTML基础--基本概念--跟着李南江学编程
- 7、前端--jQuery简介、基本选择器、基本筛选器、属性选择器、表单选择器、筛选器方法、节点操作、绑定事件
- 一般模型化关系——从模型是什么到如何起作用的基本答案
- canvas(一)基本用法
- 带你了解类型系统以及flow和typescript的基本使用
- MySQL数据库的基本操作