[OpenCV学习日记-java]-11-图形以及文字绘制

图形以及文字绘制

Mat上绘制基本几何图形和文本,包括矩形,直线,圆,椭圆,还有文本文字

Point 点对象

就和绘图的点一样,两个点构造一条直线

Point pt1 = new Point(15,30);// pt1(15,30) 坐标

绘制直线

Api函数如下:

line(Mat img, Point pt1, Point pt2, Scalar color) 
  • img:绘制图形到此Mat上
  • pt1:第一个点坐标
  • pt2:第二个点坐标
  • color :代表颜色

绘制矩形

rectangle(Mat img, Point pt1, Point pt2, Scalar color)
  • img:绘制图形到此Mat上
  • pt1:第一个点坐标
  • pt2:第二个点坐标
  • color :代表颜色

绘制圆形

circle(Mat img, Point v, int radius, Scalar color)
  • img:绘制图形到此Mat上
  • center:中心点
  • radius:半径
  • color :代表颜色

绘制椭圆形

 ellipse(Mat img, Point center, Size axes, double angle, double startAngle, double endAngle, Scalar color)
  • img:绘制图形到此Mat上
  • center:中心点
  • axes:椭圆的长轴与端州大小,单位是像素
  • angle:代表旋转角度
  • startAngle:代表开始调度大小
  • endAngle:结束角度大小
  • color :代表颜色

绘制文字

putText(Mat img, String text, Point org, int fontFace, double fontScale, Scalar color)
  • img:绘制图形到此Mat上
  • text:要绘制的文本
  • org:开始点屏幕坐标
  • fontFace:字体类型
  • fontScale:字体大小
  • color:字体颜色

结果和代码

//要绘制的Mat
Mat s1 = new Mat(600,600, CvType.CV_8UC3);
Point pt1,pt2;//定义两个点

//B:0   G:0   R:255    红色
Scalar color = new Scalar(0,0,255);

//绘制圆形
pt1 = new Point(15,30);
pt2 = new Point(155,80);
Imgproc.line(s1,pt1,pt2,color);


//绘制矩形
pt1 = new Point(80,120);
pt2 = new Point(180,180);
Imgproc.rectangle(s1,pt1,pt2,color);


//绘制圆形
pt1 = new Point(380,280);
Imgproc.circle(s1,pt1,80,color);

//绘制椭圆形
pt1 = new Point(120,280);
Size axes = new Size(100,50);
Imgproc.ellipse(s1,pt1,axes,360,0,360,color);


//绘制文字
pt1 = new Point(10,450);
Imgproc.putText(s1,"Happy new year ",pt1,Imgproc.FONT_HERSHEY_COMPLEX,2,color);

//展示
HighGui.imshow("图形",s1);

在这里插入图片描述


上一篇[OpenCV学习日记-java]-10-Canny边缘检测
下一篇[OpenCV学习日记-java]-12-霍夫变换
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Timeless小帅

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

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

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

打赏作者

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

抵扣说明:

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

余额充值