Emgu CV4图像处理之基本绘图函数6(C#)

本文测试环境:

win10  64位

vistual studio 2019  

Emgu CV 4.6.0

环境配置准备:

1 新增控制台项目,.net framework为4.7.2

2  把win-x64目录的native目录下的文件全部拷贝到项目的运行目录Debug目录下

3  项目选择x64

4 添加项目引用Emgu.CV.dll、Emgu.CV.Platform.NetFramework.dll、System.Drawing.dll和System.Runtime.InteropServices.RuntimeInformation.dll  

具体配置参考:

Emgu CV4图像处理之环境搭建1(C#)_zxy2847225301的博客-CSDN博客

下面的内容转自:EmguCV-第07讲-基本绘图函数_YADONCHEN的博客-CSDN博客

1  绘制直线

CvInvoke.Line

第一个参数img为要绘制的图像,第二个参数pt1为直线的起点,第三个参数pt2是直线的终点,第四个参数color为颜色

参考代码如下:

using Emgu.CV;
using Emgu.CV.Structure;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmguCVDemo2
{
    class Program
    {
        static void Main(string[] args)
        {
            Mat mat = new Mat("deskpic.png");
            Mat pic = mat.Clone();
            CvInvoke.Line(pic, new System.Drawing.Point(10, 10), new System.Drawing.Point(100, 100), new MCvScalar(0, 0, 255));
            CvInvoke.Imshow("test", pic);
            CvInvoke.WaitKey(0);
            Console.ReadLine();
        }
    }
}

 运行结果如下:

2  绘制圆形

CvInvoke.Circle

第一个参数img为源图片,第二个参数center为圆的中心点,第三个参数radius为圆的半径,第四个参数color为颜色

参考代码如下:

using Emgu.CV;
using Emgu.CV.Structure;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmguCVDemo2
{
    class Program
    {
        static void Main(string[] args)
        {
            Mat mat = new Mat("deskpic.png");
            Mat pic = mat.Clone();
            CvInvoke.Circle(pic, new System.Drawing.Point(300, 300), 200, new MCvScalar(0, 0, 255));
            CvInvoke.Imshow("test", pic);
            CvInvoke.WaitKey(0);
            Console.ReadLine();
        }
    }
}

运行结果如下:

3  绘制矩形

CvInvoke.Rectangle

第一个参数img为源图片,第二个参数rect为要绘制的矩形,第三个参数color为颜色

参考代码如下:new System.Drawing.Rectangle(100, 100, 400, 200)中的第一个参数100为矩形起点的x坐标,第二个参数100为矩形起点的y坐标,第三个参数400为矩形的宽,第四个参数为矩形的高

using Emgu.CV;
using Emgu.CV.Structure;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmguCVDemo2
{
    class Program
    {
        static void Main(string[] args)
        {
            Mat mat = new Mat("deskpic.png");
            Mat pic = mat.Clone();
            CvInvoke.Rectangle(pic, new System.Drawing.Rectangle(100, 100, 400, 200), new MCvScalar(0,0,255));
            CvInvoke.Imshow("test", pic);
            CvInvoke.WaitKey(0);
            Console.ReadLine();
        }
    }
}

 运行结果如下:

4 为图片添加文字

CvInvoke.PutText

 第一个参数img为源图片,第二个参数是要绘制的文本,第三个参数org为绘制文本的起点坐标,第四个参数fontFace是字体,第五个参数fontScale是字缩放的比例,第六个参数color为颜色

参考代码如下:

using Emgu.CV;
using Emgu.CV.Structure;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmguCVDemo2
{
    class Program
    {
        static void Main(string[] args)
        {
            Mat mat = new Mat("deskpic.png");
            Mat pic = mat.Clone();
            CvInvoke.PutText(pic, "put text", new System.Drawing.Point(100, 200), Emgu.CV.CvEnum.FontFace.HersheySimplex,0.5, new MCvScalar(0, 0, 255));
            CvInvoke.Imshow("test", pic);
            CvInvoke.WaitKey(0);
            Console.ReadLine();
        }
    }
}

运行结果如下:

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值