当前位置:   article > 正文

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

cvinvoke.puttext

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

CvInvoke.Line() 用于绘制线段

CvInvoke.Circle() 用于绘制圆形

CvInvoke.Ellipse() 绘制椭圆

CvInvoke.Rectangle() 绘制矩形

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

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

1、CvInvoke.Line()

  1. public static void Line(
  2. IInputOutputArray img,
  3. Point pt1,
  4. Point pt2,
  5. MCvScalar color,
  6. int thickness = 1,
  7. LineType lineType = LineType.EightConnected,
  8. int shift = 0
  9. )

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()

函数参数和用法:

  1. public static void Circle(
  2. IInputOutputArray img,
  3. Point center,
  4. int radius,
  5. MCvScalar color,
  6. int thickness = 1,
  7. LineType lineType = LineType.EightConnected,
  8. int shift = 0
  9. )

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()

参数和用法:

  1. public static void Ellipse(
  2. IInputOutputArray img,
  3. Point center,
  4. Size axes,
  5. double angle,
  6. double startAngle,
  7. double endAngle,
  8. MCvScalar color,
  9. int thickness = 1,
  10. LineType lineType = LineType.EightConnected,
  11. int shift = 0
  12. )

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(椭圆弧的结束角度)

 

其他参数不再赘述

 

还有一个重载方法

  1. public static void Ellipse(
  2. IInputOutputArray img,
  3. RotatedRect box,
  4. MCvScalar color,
  5. int thickness = 1,
  6. LineType lineType = LineType.EightConnected,
  7. int shift = 0
  8. )

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

RotatedRect box

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

  1. public RotatedRect(
  2. PointF center,
  3. SizeF size,
  4. float angle
  5. )

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()

参数和用法:

  1. public static void Rectangle(
  2. IInputOutputArray img,
  3. Rectangle rect,
  4. MCvScalar color,
  5. int thickness = 1,
  6. LineType lineType = LineType.EightConnected,
  7. int shift = 0
  8. )

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

5.CvInvoke.PutText()

参数和用法:

  1. public static void PutText(
  2. IInputOutputArray img,
  3. string text,
  4. Point org,
  5. FontFace fontFace,
  6. double fontScale,
  7. MCvScalar color,
  8. int thickness = 1,
  9. LineType lineType = LineType.EightConnected,
  10. bool bottomLeftOrigin = false
  11. )

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.(缩放因子)

举例:

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/1001631
推荐阅读
  

闽ICP备14008679号