绘线
void line(InputOutPutArray img,point pt1,Point pt2,const Scalar& color,int thickness = 1,int lineType = LINE_8,int shift = 0);
//线的样式
enum LineTypes
{
FILLED = -1,
LINE_4 = 4
LINE_8 = 8,
LINE_AA = 16
}
/****************************************************************************** * img: 绘制在那个图像上 * pt1: 起点 * pt2:终点 * color 颜色 * thickness 厚度 * lineType 线的样式 * FILLED: 线的填充 * LINE_4: 4的邻接连接线 * LINE_8:8的邻接连接线 * LINE_AA:反抗齿连接线 * shift:坐标点小数位 *******************************************************************************/
绘圆函数
void circle(InputOutPutArray img,point center,Point radius,const Scalar& color,int thickness = 1,int lineType = LINE_8,int shift = 0);
enum LineTypes
{
FILLED = -1,
LINE_4 = 4
LINE_8 = 8,
LINE_AA = 16
}
/****************************************************************************** * img: 绘制在那个图像上 * center: 圆心 * radius:半径 * color 颜色 * thickness 厚度 * -1:填充圆 * 其他值:空心 * lineType 线的样式 * FILLED: 线的填充 * LINE_4: 4的邻接连接线 * LINE_8:8的邻接连接线 * LINE_AA:反抗齿连接线 * shift:坐标点小数位 *******************************************************************************/
绘制矩形
void rectangle(InputOutPutArray img,Rect rec,const Scalar& color,int thickness = 1,int lineType = LINE_8,int shift = 0);
enum LineTypes
{
FILLED = -1,
LINE_4 = 4
LINE_8 = 8,
LINE_AA = 16
}
/****************************************************************************** * img: 绘制在那个图像上 * rec: 矩形的大小 Rect(x,y,w,h); * x,y 起始坐标 * w,h 宽度和高度 * color 颜色 * thickness 厚度 * -1:填充矩形 * 其他值:空心矩形 * lineType 线的样式 * FILLED: 线的填充 * LINE_4: 4的邻接连接线 * LINE_8:8的邻接连接线 * LINE_AA:反抗齿连接线 * shift:坐标点小数位 *******************************************************************************/
绘制椭圆
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);
enum LineTypes
{
FILLED = -1,
LINE_4 = 4
LINE_8 = 8,
LINE_AA = 16
}
/****************************************************************************** * img: 绘制在那个图像上 * center: 椭圆圆心 * axes:矩形内置椭圆 * angle:倾斜角 * startAngleL:扩展的弧度 0 * endAngle: 扩展的弧度 360 * color 颜色 * thickness 厚度 * -1:填充矩形 * 其他值:空心矩形 * lineType 线的样式 * FILLED: 线的填充 * LINE_4: 4的邻接连接线 * LINE_8:8的邻接连接线 * LINE_AA:反抗齿连接线 * shift:坐标点小数位 *******************************************************************************/
文字输入
void putText(InputOutPutArray img,Const String& text,Point org,int fontFace,double fontScale,const Scalar& color,int thickness = 1,int lineType = LINE_8,bool bottomLeftOrigin = false);
enum LineTypes
{
FILLED = -1,
LINE_4 = 4
LINE_8 = 8,
LINE_AA = 16
}
/****************************************************************************** * img: 绘制在那个图像上 * text:绘制文字 * org:文本框左下角 * fontFace: 字体 * fontScale:缩放 * color 颜色 * thickness 厚度 * -1:填充矩形 * 其他值:空心矩形 * lineType 线的样式 * FILLED: 线的填充 * LINE_4: 4的邻接连接线 * LINE_8:8的邻接连接线 * LINE_AA:反抗齿连接线 * bootomLeftOrigin: 起点位置 * true :左下角 * false:左小角 正常显示 *******************************************************************************/
//注:不识别汉字
上面写了这么多的函数,下面就开始写代码了
#include<opencv2/opencv.hpp>
using namespce std;
using namespce cv;
class shape
{
public:
shape()
:mat(imread("1.jpg")){
}
void drawLine(int x,int y = 0,int xx = 600,int yy = 600)
{
line(mat,Point(x,y),Point(xx,yy),Scalar(0,0,255),2,LINE_AA);
}
void drawCircle(int x = 300,int y = 230,int r = 10)
{
circle(mat,Point(x,y),r,Scalar(0,255,0),-1,FILLED);
}
void DrawRectangle(int x = 100,int y = 100,int w = 40,int h = 40)
{
rectangle(mat,Rect(x,y,w,h),Scalar(255,255,255),-1,LINE_4);
rectangle(mat,Rect(x - 1,y - 1,w + 2,h + 2),Scalar(255,255,255),-1,LINE_4);
}
//椭圆
void DrawEllipse(int x = 400,int y = 200,Size size = {
100,200})
{
ellipse(mat,Point(x,y),size,180,0,360,Scalar(255,0,0),1);
}
void show(string wName = 'shape')
{
imshow(wName,mat);
waitKey(0);
}
//输入文字
void DrawText()
{
putText(mat,"opencv test draw shape",Point(50,50),FONT_HERSHEY_COMPLEX,1.0,Scalar(0,0,255));
}
protected:
Mat mat;
}
int main()
{
shape* s = new shape;
s->drawLine();
s->show();
delete s;
return 0;
}
文章评论