绘制直线
@param img 输入图像
@param pt1 第一个点
@param pt2 第二个点
@param color 绘制颜色
@param thickness 线条粗细,负数则填充区域
@param lineType 画线算法,有四连通、8连通、反走样法
@param shift 坐标小数点精度
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
int thickness = 1, int lineType = LINE_8, int shift = 0);
绘制带箭头直线
@param tipLength 箭头线长度占线段长度的百分比
void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
int thickness=1, int line_type=8, int shift=0, double tipLength=0.1);
绘制矩形
@param rec 定义矩形左上角点,及其宽高
void rectangle(InputOutputArray img, Rect rec,
const Scalar& color, int thickness = 1,
int lineType = LINE_8, int shift = 0);
绘制圆形
void circle(InputOutputArray img, Point center, int radius,
const Scalar& color, int thickness = 1,
int lineType = LINE_8, int shift = 0);
绘制椭圆或弧
@param center 圆心
@param axes 长轴短轴的一半
@param angle 椭圆角度,单位 °
@param startAngle 弧的起始角度
@param endAngle 弧的结束角度
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);
举个例子吧,老丝儿
void OpencvExample::Example_Drawing(Mat &image)
{
//直线
Point pt1;
Point pt2;
pt1.x = 0;
pt1.y = 0;
pt2.x = image.cols - 1;
pt2.y = image.rows - 1;
line(image, pt1, pt2, Scalar(255,0,0), 5, 8, 0);
//带箭头的直线
pt1.x = 0;
pt1.y = image.rows - 1;
pt2.x = image.cols - 50;
pt2.y = 50;
arrowedLine(image, pt1, pt2, Scalar(255, 0, 0), 5, 8, 0, 0.1);
//矩形
Rect rect;
rect.x = 330;
rect.y = 90;
rect.width = 300;
rect.height = 300;
rectangle(image, rect, Scalar(0,0,255), 5, 8, 0);
//圆
Point center;
int radius = 30;
center.x = 431;
center.y = 291;
circle(image, center, radius, Scalar(0,255,0), 5, 8, 0);
//椭圆
Size axes = Size(60,30);
double angle = 0;
double startAngle = 0;
double endAngle = 360;
ellipse(image, center, axes, 0, 0, 360, Scalar(200,48,125), 5, 8, 0);
//扇形
axes = Size(30, 30);
center.x = 529;
center.y = 291;
ellipse(image, center, axes, 0, 270, 360, Scalar(200, 200, 125), -1, 8, 0);
imshow("dst",image);
}