Opencv -- 14图像几何形状绘制 -- 矩形、圆形、直线、椭圆

绘制矩形

在前面已经介绍过了,这里就不再重复介绍了,只把代码贴在这儿。
需要注意,若矩形填充颜色,则对应的参数的值为-1,而不填充时,参数的值大于0,表示线宽。

#include <iostream>
#include "14_opencv_mat.h"

using namespace std;

void QuickDemo::drawing_demo(Mat &image)
{
	Rect rect;
	rect.x = 130;
	rect.y = 40;
	rect.width = 200;
	rect.height = 250;
	rectangle(image, rect, Scalar(0,0, 255), 2, LINE_8, 0);

	imshow("绘制矩形", image);
}

运行效果如下:
在这里插入图片描述
除了可以绘制矩形之外,我们还可以绘制圆形。
绘制圆形可以使用函数 circle()

#include <iostream>
#include "14_opencv_mat.h"

using namespace std;

void QuickDemo::drawing_demo(Mat &image)
{
	/*
	 * 函数功能:画一个圆
	 * 函数原型:
	 * void circle(InputOutputArray img, Point center, int radius,
                       const Scalar& color, int thickness = 1,
                       int lineType = LINE_8, int shift = 0);
	 * 函数参数:
	 * img       - 输入图像
	 * center    - 圆心坐标
	 * radius    - 圆的半径
	 * color     - 圆的颜色 
	 * thickness - 圆轮廓的厚度,如果为正值。负值,比如#FILLED,表示要画一个填充的圆。
	 * lineType  - 线形,默认为LINE_8
	 * shift     - 中心坐标和半径值的小数位数。
	 */

	circle(image,Point(200,100),100,Scalar(0,0,255),2,LINE_8,0);
	imshow("绘制圆形", image);
}

运行效果如下:
在这里插入图片描述
可以使用函数 line()来绘制直线

void QuickDemo::line_demo(Mat& image)
{
	/*
	 *  函数功能:绘制连接两点的线段。
	 *  函数原型:void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
                            int thickness = 1, int lineType = LINE_8, int shift = 0);

		函数参数:img  - 输入图像。
				  pt1 - 线段的第一点。
				  pt2 - 线段的第二点。
				color - 线条颜色。
			thickness - 线条厚度。
			 lineType - 线的类型,是否为反锯齿
				shift - 点坐标的小数位数。
	 */
	line(image,Point(20,20), Point(70, 70),Scalar(0,255,255),2);
	imshow("line_demo", image);
}

运行效果如下:
在这里插入图片描述
可以使用函数 ellipse()来绘制椭圆
估计不常用,就不学了,用到了再来补充。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

xuechanba

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

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

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

打赏作者

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

抵扣说明:

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

余额充值