Color = 1 AnyDepth = 2 AnyColor = 4 无关 无关 任何类型 无关 任何类型 无关
2. 保存图片:
Image
Image
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
如果需要转成Mat类型,即Image
获取ImageBox图片代码为:
Image byte> _picture = new Image byte>(new Bitmap( imageBox1.Image.Bitmap)); 5. 绘画图形: 在图像上绘画一些图形是非常常见的,接下来介绍常用到的绘画方法。 Image 在Image 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 接下来介绍Image 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所示。