Opencv图形绘制与文字输出

绘线

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;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我只爱炸鸡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值