EMGUCV基础(7)

2019-04-17 15:37

Color = 1 AnyDepth = 2 AnyColor = 4 无关 无关 任何类型 无关 任何类型 无关

2. 保存图片:

Image:

Image中采用函数public override void Save(string fileName)来保存图片。String fileName参数和创建图片的String fileName一样。这边不再重复介绍。

Mat:

Mat类中的public void Save(string fileName)函数用于保存图片。

3. 显示图片:

显示图片通常使用控件ImageBox(EmguCv 控件)或者PictureBox(.Net控件);

PictureBox显示图片的类型为.Net类型,ImageBox显示图片为EmguCv图像类型。常见错误如图3.4,3.5所示。

图3.4 PictureBox 无法显示EmguCv图像类型

图3.5 ImageBox无法显示.Net类型

正确使用方法:

如图3.6所示。

图3.6 显示图像正确方法

4. 获得控件中的图片:(这边主要讲解PictureBox和ImageBox控件,其他控件实现方法类似)

PictureBox控件:

PictureBox显示的图片为Bitmap类型,则获得PictureBox控件中的代码如下:

Image _picture = new Image(new Bitmap( pictureBox1.Image));

如果需要转成Mat类型,即Image类型转成Mat类型。 ImageBox控件:

获取ImageBox图片代码为:

Image

byte>

_picture

=

new

Image

byte>(new

Bitmap( imageBox1.Image.Bitmap)); 5. 绘画图形:

在图像上绘画一些图形是非常常见的,接下来介绍常用到的绘画方法。 Image:

在Image 类存在draw()方法来提供用户绘画图形。具体使用方法解析:

public virtual void Draw(Rectangle rect, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0);//绘画矩形

参数解析:

Rectangle rect:需要绘画的矩形。 TColor color:画笔颜色类型。 int thickness = 1:画笔宽度。

LineType lineType = LineType.EightConnected:线的类型,一个Emgu.CV.Cvenum的标识符。如表3.2。

int shift = 0:部分比特数中心坐标和半径值,默认为0。

表 3.2 线类型

表示符 解析 FourConnected = 4 四方向连接

EightConnected = 8 八方向连接

AntiAlias = 16 锯齿线连接

public virtual void Draw(CircleF circle, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0);//绘画圆形。

参数解析:

CircleF circle:需要绘画的圆。 TColor color:画笔颜色类型。 int thickness = 1:画笔宽度。

LineType lineType = LineType.EightConnected:线的类型,一个Emgu.CV.Cvenum的标识符。如表3.2。

int shift = 0:部分比特数中心坐标和半径值,默认为0。

通过上面两种函数参数的解析,相信读者已经对绘画图像的参数有所了解,第一个为所需要绘画图形的类型。第二个为画笔颜色,第三个为画笔宽度,第四个线条类型,等一些参数。基本绘画参数就是这些。

public virtual void Draw(string message, Point bottomLeft, FontFace fontFace, double fontScale, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, bool bottomLeftOrigin = false);//在图像上绘画字符串。

参数解析:

string message:绘画字符串的内容。 Point bottomLeft:字符串左上角的点。

FontFace fontFace:字体类型。一个Emgu.Cv.Cvenum的标识符。具体如图3.7所示。

double fontScale:字体放大倍数。 TColor color:画笔颜色类型。 int thickness = 1:画笔宽度。

LineType lineType = LineType.EightConnected:线的类型,一个Emgu.CV.Cvenum的标识符。如表3.2。

bool bottomLeftOrigin = false:true表示图像数据以左下角为源。false:左上角为源。

图 3.7 文字类型标识符

实现代码:

如图3.8所示。

图3.8 绘画代码

实现效果:

如图3.9所示。

图 3.9 实现效果

经过上面的学习,相信大家已经对Image Draw()方法基本了解。

接下来介绍Image DrawPolyline()方法。从字面上可以猜测这个方法为画多边直线的方法。

public void DrawPolyline(Point[] pts, bool isClosed, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0);//绘画一个多边形。

public void DrawPolyline(Point[][] pts, bool isClosed, TColor color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0);//绘画多个多边形。

参数解析:

Point[] pts:一维点集合。(Point[][] pts:二维点集合)。 bool isClosed:是否为闭合。即首点和末点是否连接。 TColor color:画笔颜色类型。 int thickness = 1:画笔宽度。

LineType lineType = LineType.EightConnected:线的类型,一个Emgu.CV.Cvenum的标识符。为如表3.2。

int shift = 0:部分比特数中心坐标和半径值,默认为0。

实现代码:

如图3.10所示。


EMGUCV基础(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017年Fenbi模考大赛第七季试题及答案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: