C#+EmguCV 在图像上进行基本绘图

EmguCV主要的绘图函数有一下几种:

CvInvoke.Line() 用于绘制线段

CvInvoke.Circle() 用于绘制圆形

CvInvoke.Ellipse() 绘制椭圆

CvInvoke.Rectangle() 绘制矩形

CvInvoke.PutText() 在图像上显示文字

来看看他们各个函数的参数和用法

1、CvInvoke.Line()

public static void Line(
	IInputOutputArray img,
	Point pt1,
	Point pt2,
	MCvScalar color,
	int thickness = 1,
	LineType lineType = LineType.EightConnected,
	int shift = 0
)

Parameters(参数含义)

img

Type: Emgu.CV.IInputOutputArray
The image(被绘制的图片)

pt1

Type: System.Drawing.Point
First point of the line segment(线段的第一个点,即起始位置)

pt2

Type: System.Drawing.Point
Second point of the line segment(线段的第二个点,即结束位置)

color

Type: Emgu.CV.Structure.MCvScalar
Line color(线段颜色)

thickness (Optional)

Type: System.Int32
Line thickness.(线段的宽度,以像素为单位)

lineType (Optional)

Type: Emgu.CV.CvEnum.LineType
Type of the line: 8 (or 0) - 8-connected line. 4 - 4-connected line. CV_AA - antialiased line.(四通道或八通道类型的枚举)

shift (Optional)

Type: System.Int32
Number of fractional bits in the point coordinates(点坐标中的分数位数,此参数可忽略不写)

这里比较要注意的地方是结构体CvScalar,他的用法如下:

CvScalar cvScalar( double val0, double val1=0,double val2=0, double val3=0 );

//最通用的,可初始化0-4个通道

举例:

a) 存放单通道图像中像素:cvScalar(255);

b) 存放三通道图像中像素:cvScalar(255,255,255);

2. inline CvScalar cvRealScalar( double val0 );

另外,他的通道顺序是BGR,这点需要小心。

 

2、CvInvoke.Circle()

函数参数和用法:

public static void Circle(
	IInputOutputArray img,
	Point center,
	int radius,
	MCvScalar color,
	int thickness = 1,
	LineType lineType = LineType.EightConnected,
	int shift = 0
)

Parameters

center

Type: System.Drawing.Point
Center of the circle (圆心的位置)

radius

Type: System.Int32
Radius of the circle.(圆形的半径)

thickness (Optional)

Type: System.Int32
Thickness of the circle outline if positive, otherwise indicates that a filled circle has to be drawn(圆形轮廓的宽度,如果是负数,那就是一个实心圆,否则就是空心圆)

其他的参数已经介绍过,不再赘述

3、CvInvoke.Ellipse()

参数和用法:

public static void Ellipse(
	IInputOutputArray img,
	Point center,
	Size axes,
	double angle,
	double startAngle,
	double endAngle,
	MCvScalar color,
	int thickness = 1,
	LineType lineType = LineType.EightConnected,
	int shift = 0
)

Parameters

img

Type: Emgu.CV.IInputOutputArray
Image

center

Type: System.Drawing.Point
Center of the ellipse

axes

Type: System.Drawing.Size
Length of the ellipse axes(横轴和纵轴的长度)

angle

Type: System.Double
Rotation angle(横轴旋转的角度)

startAngle

Type: System.Double
Starting angle of the elliptic arc(椭圆弧的起始角度)

endAngle

Type: System.Double
Ending angle of the elliptic arc(椭圆弧的结束角度)

 

其他参数不再赘述

 

还有一个重载方法

public static void Ellipse(
	IInputOutputArray img,
	RotatedRect box,
	MCvScalar color,
	int thickness = 1,
	LineType lineType = LineType.EightConnected,
	int shift = 0
)

这里需要注意第二个参数的用法

RotatedRect box

Type: Emgu.CV.Structure.RotatedRect
The box the define the ellipse area(定义椭圆的区域)

public RotatedRect(
	PointF center,
	SizeF size,
	float angle
)

Parameters

center

Type: System.Drawing.PointF
The center of the box

size

Type: System.Drawing.SizeF
The size of the box

angle

Type: System.Single
The angle of the box in degrees. Possitive value means counter-clock wise rotation(旋转角度)

 

 

4、CvInvoke.Rectangle()

参数和用法:

public static void Rectangle(
	IInputOutputArray img,
	Rectangle rect,
	MCvScalar color,
	int thickness = 1,
	LineType lineType = LineType.EightConnected,
	int shift = 0
)

这几个参数比较简单,不再赘述

5.CvInvoke.PutText()

参数和用法:

public static void PutText(
	IInputOutputArray img,
	string text,
	Point org,
	FontFace fontFace,
	double fontScale,
	MCvScalar color,
	int thickness = 1,
	LineType lineType = LineType.EightConnected,
	bool bottomLeftOrigin = false
)

Parameters

img

Type: Emgu.CV.IInputOutputArray
Input image

text

Type: System.String
String to print(需要显示的文字)

org

Type: System.Drawing.Point
Coordinates of the bottom-left corner of the first letter(第一个字符左下角的坐标)

fontFace

Type: Emgu.CV.CvEnum.FontFace
Font type.(字体)

fontScale

Type: System.Double
Font scale factor that is multiplied by the font-specific base size.(缩放因子)

举例:

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值