首页 > 编程语言 >C#+OpenCV基础(十四)_绘制像素、图形、文字

C#+OpenCV基础(十四)_绘制像素、图形、文字

时间:2024-07-10 17:30:54浏览次数:20  
标签:LineTypes mat Point C# 像素 OpenCV lineType thickness 线条

1、绘制直线

/// <summary>
/// 绘制直线
/// </summary>
/// <param name="mat">图片</param>
/// <param name="startPoint">线段的第一个点</param>
/// <param name="endPoint">线段的第二个点</param>
/// <param name="color">线条颜色</param>
/// <param name="thickness">线条宽度</param>
/// <param name="lineType">线条类型</param>
/// <param name="shift">偏移量</param>
/// <returns></returns>
public static Mat DrawLine(Mat mat, Point startPoint, Point endPoint, Scalar color,
    int thickness = 1, LineTypes lineType = LineTypes.Link8, int shift = 0)
{
    Cv2.Line(mat, startPoint, endPoint, color, thickness, lineType, shift);
    return mat;
}

2、绘制椭圆

/// <summary>
/// 绘制椭圆
/// </summary>
/// <param name="mat">图片</param>
/// <param name="center">圆点</param>
/// <param name="axes">半径长度;new Size(A1,A2)</param>
/// <param name="angle">椭圆偏移角度;>0顺时针,<0逆时针 </param>
/// <param name="startAngle">椭圆起始角度;>0 </param>
/// <param name="endAngle">椭圆终止角度;<360 </param>
/// <param name="color">椭圆线条颜色</param>
/// <param name="thickness">椭圆线条宽度;负数代表填充</param>
/// <param name="lineType">椭圆线条类型</param>
/// <param name="shift">偏移量</param>
/// <returns></returns>
public static Mat DrawEllipse(Mat mat, Point center, Size axes, double angle, double startAngle, double endAngle, Scalar color,
    int thickness = 1, LineTypes lineType = LineTypes.Link8, int shift = 0)
{
    Cv2.Ellipse(mat, center, axes, angle, startAngle, endAngle, color, thickness, lineType, shift);
    return mat;
}

3、绘制圆

/// <summary>
/// 绘制圆
/// </summary>
/// <param name="mat">图片</param>
/// <param name="center">圆心坐标</param>
/// <param name="radius">圆半径</param>
/// <param name="color">圆线条颜色</param>
/// <param name="thickness">圆线条宽度;负数代表填充</param>
/// <param name="lineType">圆线条类型</param>
/// <param name="shift">偏移量</param>
/// <returns></returns>
public static Mat DrawCircle(Mat mat, Point center, int radius, Scalar color,
    int thickness = 1, LineTypes lineType = LineTypes.Link8, int shift = 0)
{
    Cv2.Circle(mat, center, radius, color, thickness, lineType, shift);
    return mat;
}

4、绘制矩形

/// <summary>
/// 绘制矩形
/// </summary>
/// <param name="mat">图片</param>
/// <param name="pt1">顶点1</param>
/// <param name="pt2">顶点1相对应的顶点2</param>
/// <param name="color">矩形线条颜色</param>
/// <param name="thickness">矩形线条宽度;负数代表填充</param>
/// <param name="lineType">矩形线条类型</param>
/// <param name="shift">偏移量</param>
/// <returns></returns>
public static Mat DrawRectangle(Mat mat, Point pt1, Point pt2, Scalar color,
    int thickness = 1, LineTypes lineType = LineTypes.Link8, int shift = 0)
{
    Cv2.Rectangle(mat, pt1, pt2, color, thickness, lineType, shift);
    return mat;
}

5、绘制多边形

/// <summary>
/// 绘制多边形
/// </summary>
/// <param name="mat">图片</param>
/// <param name="pts">点位坐标</param>
/// <param name="isClosed">是否闭合线条</param>
/// <param name="color">多边形线条颜色</param>
/// <param name="thickness">多边形线条宽度;负数代表填充</param>
/// <param name="lineType">多边形线条类型</param>
/// <param name="shift">偏移量</param>
/// <returns></returns>
public static Mat DrawPolylines(Mat mat, IEnumerable<IEnumerable<Point>> pts, bool isClosed, Scalar color,
    int thickness = 1, LineTypes lineType = LineTypes.Link8, int shift = 0)
{
    //OpenCvSharp.Point[][] points = {
    //    new OpenCvSharp.Point[] { new OpenCvSharp.Point(50, 50), new OpenCvSharp.Point(50, 100), new OpenCvSharp.Point(100, 100) },
    //    new OpenCvSharp.Point[] { new OpenCvSharp.Point(200, 50), new OpenCvSharp.Point(250, 50), new OpenCvSharp.Point(250, 150), new OpenCvSharp.Point(200, 150) }
    //};
    Cv2.Polylines(mat, pts, isClosed, color, thickness, lineType, shift);
    return mat;
}

6、绘制文本-不支持中文

/// <summary>
/// 绘制文本-不支持中文
/// </summary>
/// <param name="mat">图片</param>
/// <param name="text">文字</param>
/// <param name="org">文本左上角的起始坐标</param>
/// <param name="fontFace">字体大小</param>
/// <param name="fontScale">字体缩放</param>
/// <param name="color">字体颜色</param>
/// <param name="thickness">字体线条宽度</param>
/// <param name="lineType">字体线条类型</param>
/// <param name="bottomLeftOrigin">是否左下对齐</param>
/// <returns></returns>
public static Mat DrawText(Mat mat, string text, Point org, HersheyFonts fontFace, double fontScale, Scalar color,
    int thickness = 1, LineTypes lineType = LineTypes.Link8, bool bottomLeftOrigin = false)
{
    Cv2.PutText(mat, text, org, fontFace, fontScale, color, thickness, lineType, bottomLeftOrigin);
    return mat;
}

7、绘制文本-支持中文

/// <summary>
/// 绘制文本-支持中文
/// </summary>
/// <param name="bitmap">图片</param>
/// <param name="text">文字内容</param>
/// <param name="font">字体信息;new Font("宋体", 8)</param>
/// <param name="smoothingMode">字体平滑模式;SmoothingMode.AntiAlias</param>
/// <param name="org">位置;new System.Drawing.Point(10, 560)</param>
/// <param name="brush">字体颜色;System.Drawing.Brushes.White</param>
/// <returns></returns>
public static Bitmap DrawText_Utf8(Bitmap bitmap, string text, System.Drawing.Font font, SmoothingMode smoothingMode,
    System.Drawing.Point org, System.Drawing.Brush brush)
{
    using (var graphics = Graphics.FromImage(bitmap))
    {
        graphics.SmoothingMode = smoothingMode;
        graphics.DrawString(text, font, brush, org);
    }
    return bitmap;
}

标签:LineTypes,mat,Point,C#,像素,OpenCV,lineType,thickness,线条
From: https://www.cnblogs.com/qq2806933146xiaobai/p/18294644

相关文章

  • Using Multipath TCP to enhance bandwidth and withstand outages
    https://blog.coursemonster.com/using-multipath-tcp-to-enhance-bandwidth-and-withstand-outages/  UsingMultipathTCPtoenhancebandwidthandwithstandoutagesPostedbyMarbenzAntonioonJune16,2022MultiPathTCP(MPTCP) allowsyoutobundlenumero......
  • Setup Multipath TCP
    https://medium.com/@iheb.zannina/setup-mptcpv1-in-linux-v5-6-9b5e48173b5b  SetupMultipathTCP IhebZannina·Follow5minread·Mar23,2023 1   AbstractMPTCP,orMultipat......
  • PCA(主成分分析)--降维的基础算法
    一.原理简介PCA主成分分析,是一种使用较为广泛的数据降维算法,主要思想是将n维数据特征映射到k维上,这k维全新的正交数据特征称为主成分;PCA的工作就是从原始的空间中顺序地找一组相互正交的坐标轴,新的坐标轴的选择与数据本身是密切相关的。其中,第一个新坐标轴选择是原始数据......
  • 【Pytorch实用教程】transformer中创建嵌入层的模块nn.Embedding的用法
    文章目录1.nn.Embedding的简单介绍1.1基本用法1.2示例代码1.3注意事项2.通俗的理解num_embeddings和embedding_dim2.1num_embeddings2.2embedding_dim2.3使用场景举例结合示例1.nn.Embedding的简单介绍nn.Embedding是PyTorch中的......
  • 视频共享交换平台LntonCVS视频监控平台智慧加油站安全管理方案
    加油站作为危化品行业的一部分,日常的加油和卸油作业安全至关重要。目前国内加油站的管理主要依赖于人为管控、监控摄像头和人工巡检,这些方法存在效率低下和反应滞后的问题。为了有效应对安全风险,急需引入人工智能、物联网和大数据技术,实现从“人工监督”向“智能监控”的升级,强......
  • 易优eyoucms在手机端下,访问PC端自动跳转手机网站的代码
    首先要区分网站是自适应还是分离式模板,比如:自适应=PC端和手机端共用模板,分离式=PC端和手机端分开模板以下代码只需在PC端模板里添加,移动端模板不需要添加。如果是分离式模板,请在网站模板里的</head>之前加上以下代码: <metahttp-equiv="mobile-agent"content="format=xhtml;url......
  • 易优CMS如何防止网站模板文件被仿盗?
    【操作步骤】1、先在模板目录/template创建相应的子目录,比如:style12、将要pc或mobile等模板目录文件拷贝到style13、前往后台的【基本信息】-【核心设置】里的前台模板风格的下拉可以看到相关的风格目录,即可进行切换;4、如果想做到模板文件路径避免暴露,建议将模板文件里的sk......
  • 易优CMS模板标签arcview单条文档输出单页模型栏目的详细内容
    [基础用法]标签:arcview描述:获取单条文档数据用法:{eyou:arcviewaid='文档ID'}<ahref="{$field.arcurl}">{$field.title}</a>{/eyou:arcview} 属性:aid=''指定文档ID,如果没有指定则获取当前文档内容页的文档IDid=''可以任意指定循环里的变量名替代field,假设id='field......
  • 题解:P10732 [NOISG2019 Prelim] Palindromic FizzBuzz
    题解:P10732[NOISG2019Prelim]PalindromicFizzBuzz题意题意十分明了,给予你一个区间,判断区间中每一个数是否是回文数。思路思路比较简单,首先将每一个数按每一位放入一个数组中,顺序无论由前到后和由后到前都可以。接下来将数组折半循环,判断前后是否一样。一样的话是回文数,......
  • linux关于CPU使用率以及psutil真正计算CPU使用率的调研
    不一定准确,只是个人的分析CPU使用率mpstat-u通过查看每个CPU核心的用户进程使用时间(%usr)来计算CPU使用率的。它只考虑了用户进程的CPU使用情况,而不考虑内核进程的CPU使用情况。 这种计算方式会更大CPU使用率=2.19+4.57=6.76 Top将用户进程(us)和内核进程(sy)的CPU使用时间......