OpenCV based tutorial - drawing functions [straightforward]

Foreword

Blog can learn by following two methods to draw text on the image

OPenCV Basics Tutorial - Draw text

https://blog.csdn.net/Gary_ghw/article/details/103746662

https://blog.csdn.net/Gary_ghw/article/details/103746709

However, in practice, the task will encounter in the image rendering images, OpenCV provides the corresponding function is easy to realize

Here, we will learn cv :: line (), cv :: rectangle (), cv :: circle (), cv :: ellipse (), cv :: polylines () function


1, drawing a straight line [class] cv :: line

void cv::line(
    CV_IN_OUT Mat& img, // 输入输出图像
    Point pt1, // 直线起点坐标
    Point pt2, // 直线终点坐标
    const Scalar& color, // 直线颜色
    int thickness=1, // 直线宽度,有默认值1
    int lineType=8, // 直线类型,默认值为8
    int shift=0 // 直线的精度,默认为0
);

2, draw a rectangle [cv :: rectangle]

void cv::rectangle(
    CV_IN_OUT Mat& img,
    Point pt1, // 矩形的左上顶点坐标
    Point pt2, // 矩形的右下顶点坐标
    const Scalar& color,
    int thickness=1, //  当thickness=-1时表示填充矩形
    int lineType=8,
    int shift=0
);

// draws the rectangle outline or a solid rectangle covering rec in the image
void cv::rectangle(
    CV_IN_OUT Mat& img,
    Rect rec, // 使用rec函数指定矩形起始点和长宽信息
    const Scalar& color,
    int thickness=1,
    int lineType=8,
    int shift=0
);

It can be seen that there are two types of parameters passed by:

One is a specified point Point class , the other is used to specify the starting point Rect rectangle function, length, width

3. Draw a circle [cv :: circle]

void cv::circle(
    CV_IN_OUT Mat& img,
    Point center, // 圆心坐标
    int radius, // 半径大小
    const Scalar& color,
    int thickness=1,
    int lineType=8,
    int shift=0
);

4, cv :: ellipse draw an ellipse []

void cv::ellipse(
    CV_IN_OUT Mat& img,
    Point center, // 椭圆中心坐标
    Size axes, // 椭圆的尺寸 即长短轴
    double angle, // 椭圆长轴偏离角度(顺时针)
    double startAngle, // 绘制椭圆起始角度(顺时针)
    double endAngle, // 绘制椭圆终点角度 若startAngle为0 && endAngle为360,则表示整个椭圆
    const Scalar& color,
    int thickness=1,
    int lineType=8,
    int shift=0
);

5, draw polylines polygons [cv :: polylines]

void cv::polylines(
    Mat& img,
    const Point** pts, // 多边形顶点坐标数组
    const int* npts, // 多边形顶点个数
    int ncontours, // 待绘制折线数
    bool isClosed, // 多边形是否闭合(折线是否相连)
    const Scalar& color,
    int lineType=8,
    int shift=0
);

void cv::polylines(
    InputOutputArray img,
    InputArrayOfArrays pts, // 多边形顶点数组
    bool isClosed, // 多边形是否闭合(折线是否相连)
    const Scalar& color,
    int lineType=8,
    int shift=0
);

It can be seen that there are two types of parameters passed by:

One is used to specify a pointer points Point class , the other is a memory array of polygon vertex information

Published 12 original articles · won praise 27 · views 781

Guess you like

Origin blog.csdn.net/Gary_ghw/article/details/103753115