1.直线
1.1 API
CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,int thickness = 1, int lineType = LINE_8, int shift = 0);
参数 |
含义 |
---|
img(image) |
绘制多边形的画布,数据类型Mat |
pt1(point1) |
端点1 |
pt2(point2) |
端点2 |
color |
绘制线条的颜色 |
thickness |
绘制线条的粗细 |
lineType |
绘制线条的连通类型 |
shift |
坐标点小数点位数(not important) |
1.2 连通类型
enum LineTypes {
FILLED = -1,
LINE_4 = 4,
LINE_8 = 8,
LINE_AA = 16
};
- LINE_4与LINE_8差别不大,而LINE_AA的抗锯齿效果显著
2.正矩形
2.1API
CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2,
const Scalar& color, int thickness = 1,
int lineType = LINE_8, int shift = 0);
参数 |
含义 |
---|
img(image) |
绘制多边形的画布,数据类型Mat |
pt1(point1) |
左上角端点 |
pt2(point2) |
右下角端点 |
color |
绘制线条的颜色 |
thickness |
绘制线条的粗细。若取负值,则表示进行填充 |
lineType |
绘制线条的连通类型 |
shift |
坐标点小数点位数(not important) |
CV_EXPORTS_W void rectangle(InputOutputArray img, Rect rec,
const Scalar& color, int thickness = 1,
int lineType = LINE_8, int shift = 0);
参数 |
含义 |
---|
img(image) |
绘制多边形的画布,数据类型Mat |
rec(rect) |
一个矩形 |
color |
绘制线条的颜色 |
thickness |
绘制线条的粗细。若取负值,则表示进行填充 |
lineType |
绘制线条的连通类型 |
shift |
坐标点小数点位数(not important) |
3.圆形
3.1 API
CV_EXPORTS_W void circle(InputOutputArray img, Point center, int radius,
const Scalar& color, int thickness = 1,
int lineType = LINE_8, int shift = 0);
参数 |
含义 |
---|
img(image) |
绘制多边形的画布,数据类型Mat |
center |
圆心坐标 |
radius |
半径 |
color |
绘制线条的颜色 |
thickness |
绘制线条的粗细。若取负值,则表示进行填充 |
lineType |
绘制线条的连通类型 |
shift |
坐标点小数点位数(not important) |
4.椭圆
4.1 API
CV_EXPORTS_W void ellipse(InputOutputArray img, Point center, Size axes,
double angle, double startAngle, double endAngle,
const Scalar& color, int thickness = 1,
int lineType = LINE_8, int shift = 0);
参数 |
含义 |
---|
img(image) |
绘制多边形的画布,数据类型Mat |
center |
圆心坐标 |
axes |
(x方向上半轴长,y方向上半轴长) |
angle |
顺时针偏角 |
startAngle |
以x方向上的正半轴为起点,偏移一定角度后的起点,从此起点开始画椭圆 |
endAngle |
以x方向上的正半轴为起点,偏移一定角度后的终点,到此为止结束画椭圆 |
color |
绘制线条的颜色 |
thickness |
绘制线条的粗细。若取负值,则表示进行填充 |
lineType |
绘制线条的连通类型 |
shift |
坐标点小数点位数(not important) |
4.2 效果
Mat canvas(Size(1000,1000),CV_8U,Scalar(255));
ellipse(canvas,Point2f(500,500),Size(50,100),0,0,90,Scalar(0,0,0),5);
imshow("canvas",canvas);
waitKey();
Mat canvas(Size(1000,1000),CV_8U,Scalar(255));
ellipse(canvas,Point2f(500,500),Size(50,100),20,0,360,Scalar(0,0,0),5);
imshow("canvas",canvas);
waitKey();
Mat canvas(Size(1000,1000),CV_8U,Scalar(255));
ellipse(canvas,Point2f(500,500),Size(50,100),20,0,180,Scalar(0,0,0),5);
imshow("canvas",canvas);
waitKey();
5 斜矩形
5.1 API(通过RotatedRect类和line函数实现)
class CV_EXPORTS RotatedRect
{
public:
RotatedRect();
RotatedRect(const Point2f& center, const Size2f& size, float angle);
RotatedRect(const Point2f& point1, const Point2f& point2, const Point2f& point3);
void points(Point2f pts[]) const;
Rect boundingRect() const;
Rect_<float> boundingRect2f() const;
Point2f center;
Size2f size;
float angle;
};
void drawRotatedRect(InputOutputArray img, RotatedRect rRect,const Scalar& color, int thickness = 1,int lineType = LINE_8, int shift = 0){
Point2f vertices[4];
rRect.points(vertices);
for(int i=0;i<4;i++){
line(img,vertices[i],vertices[(i+1)%4],color,lineType,shift);
}
}
6.多边形
6.1 API
绘制方式一
CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts,
bool isClosed, const Scalar& color,
int thickness = 1, int lineType = LINE_8, int shift = 0 );
参数 |
含义 |
---|
img(image) |
绘制多边形的画布,数据类型Mat |
pts(points) |
多边形角点的坐标点集,数据类型vector<Point>或vector<vector<Point>> ,若为vector<Point2f>或vector<vector<Point2f>> 会报错 |
isClosed |
多边形是否闭合,如果isClosed为真,那么pts的最后一个点将和第一个点连起来,否则轮廓被认为是不封闭的。 |
color |
绘制线条的颜色 |
thickness |
绘制线条的粗细。若取负值,则表示进行填充 |
lineType |
绘制线条的连通类型 |
shift |
坐标点小数点位数(not important) |
绘制方式二
CV_EXPORTS void polylines(InputOutputArray img, const Point* const* pts, const int* npts,
int ncontours, bool isClosed, const Scalar& color,
int thickness = 1, int lineType = LINE_8, int shift = 0 );
参数 |
含义 |
---|
img(image) |
绘制多边形的画布,数据类型Mat |
pts(points) |
多个多边形的角点坐标点集的地址的数组。如果有3个四边形的角点坐标点集Point[3][4],那么pts={Point[0][0],Point[1][0],Point[2][0],} |
npts(number points) |
多个多边形的角点坐标点集的元素个数排列成的数组,用来指示需要用到pts[i]中的几个元素。如果有3个四边形的角点坐标点集Point[3][4],那么npts={4,4,4,} |
ncontours |
多边形的数量 |
isClosed |
多边形是否闭合,如果isClosed为真,那么pts的最后一个点将和第一个点连起来,否则轮廓被认为是不封闭的。 |
color |
绘制线条的颜色 |
thickness |
绘制线条的粗细。若取负值,则表示进行填充 |
lineType |
绘制线条的连通类型 |
shift |
坐标点小数点位数(not important) |
打开App,阅读手记