四,opencv2.x模块core介绍(三)

一,opencv模块core内容第三部分——Drawing Functions(绘图函数)

绘图函数可以再任意深度的矩阵(图像)上工作。这些函数就是在图像矩阵上绘出特定的图像。主要有以下几种简单的绘图功能。

  1. 绘制文字putText
  2. 绘制矩形rectangle
  3. 绘制圆形circle
  4. 绘制椭圆ellipse
  5. 绘制线段line
  6. 绘制箭头arrowedLine
  7. 绘制曲线polylines
  8. 其余一些帮助函数clipLine, ellipse2Poly, fillConvexPoly, fillPoly, getTextSize, InitFont

二,具体绘制函数详解

  1. 绘制文字putText
    1
    C++: void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false )

在目标图像上写上自己指定的字符串。
其中部分参数详解:
org——文字框左下角在目标图像的坐标,相当于字符串的位置坐标
fontFace——字体类型可能有以下几种:FONT_HERSHEY_SIMPLEX, FONT_HERSHEY_PLAIN, FONT_HERSHEY_DUPLEX, FONT_HERSHEY_COMPLEX, FONT_HERSHEY_TRIPLEX, FONT_HERSHEY_COMPLEX_SMALL, FONT_HERSHEY_SCRIPT_SIMPLEX, or FONT_HERSHEY_SCRIPT_COMPLEX
fontScale——字体大小。相对于基本大小的缩放
color——字体颜色
thickness——字符串线条粗细
lineType——线型
bottomLeftOrigin——确定字符串图像的原点是坐下点还是左上点。
通常会通过辅助函数getTextSize()来帮助绘图。

  1. 绘制矩形rectangle
    1
    2
    C++: void rectangle(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
    C++: void rectangle(Mat& img, Rect rec, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )

在目标图像上绘制一个简单的确定粗细的矩形框,或者是填充矩形。

  1. 绘制圆形circle

    1
    C++: void circle(Mat& img, Point center, int radius, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
  2. 绘制椭圆ellipse

    1
    2
    C++: void ellipse(Mat& img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
    C++: void ellipse(Mat& img, const RotatedRect& box, const Scalar& color, int thickness=1, int lineType=8)
  3. 绘制线段line

    1
    C++: void line(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
  4. 绘制箭头arrowedLine

    1
    C++: void arrowedLine(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int line_type=8, int shift=0, double tipLength=0.1)
  5. 绘制曲线polylines

    1
    2
    C++: void polylines(Mat& img, const Point** pts, const int* npts, int ncontours, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )
    C++: void polylines(InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0 )

部分参数详解
pts——多边形曲线的数组
npts——多边形定点计数的数组
ncontours——曲线的数量
isClosed——决定绘制曲线是否闭合。
该函数可以画出一根或多跟曲线。

文章目录
  1. 1. 一,opencv模块core内容第三部分——Drawing Functions(绘图函数)
  2. 2. 二,具体绘制函数详解
,