[OpenCV3编程入门读书笔记]基本图像绘制(4)

这篇博客详细介绍了OpenCV3中用于图像绘制的各种函数,包括line函数用于绘制直线,ellipse函数用于绘制椭圆,rectangle函数用于绘制矩形,circle函数用于绘制圆形,以及fillPoly和polylines函数用于绘制填充和不填充的多边形。每个函数都配合实例进行了解释。
摘要由CSDN通过智能技术生成

目录

 

用于绘制直线的line函数;

用于绘制椭圆的ellipse函数;

用于绘制矩形的rectangle函数;

用于绘制圆形的circle函数;

用于绘制填充多边形的fillPoly函数和不填充多边形polylines函数;


 

每个函数第一个部分是源码中的函数定义,第二个部分辅以一个小例子。

用于绘制直线的line函数;

/** @brief Draws a line segment connecting two points.

The function line draws the line segment between pt1 and pt2 points in the image. The line is
clipped by the image boundaries. For non-antialiased lines with integer coordinates, the 8-connected
or 4-connected Bresenham algorithm is used. Thick lines are drawn with rounding endings. Antialiased
lines are drawn using Gaussian filtering.

@param img Image.
@param pt1 First point of the line segment.
@param pt2 Second point of the line segment.
@param color Line color.
@param thickness Line thickness.
@param lineType Type of the line. See #LineTypes.
@param shift Number of fractional bits in the point coordinates.
 */
CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
                     int thickness = 1, int lineType = LINE_8, int shift = 0);

 

例子:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;


int main() {
	Mat image = Mat::zeros(300, 300, CV_8UC3);
	line(image, Point(50, 50), Point(250, 250), Scalar(0, 255, 0), 2, 8);
	line(image, Point(250, 50), Point(50, 250), Scalar(0, 255, 0), 2, 8);
	imshow("绘制图像", image);
	waitKey(0);
}

用于绘制椭圆的ellipse函数;

/**
@param img Image.
@param center Center of the ellipse.
@param axes Half of the size of the ellipse main axes.
@param angle Ellipse rotation angle in degrees.
@param startAngle Starting angle of the elliptic arc in degrees.
@param endAngle Ending angle of the elliptic arc in degrees.
@param color Ellipse color.
@param thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that
a filled ellipse sector is to be drawn.
@param lineType Type of the ellipse boundary. See #LineTypes
@param shift Number of fractional bits in the coordinates of the center and values of axes.
 */
CV_EXPORTS_W void ellipse(InputOutputArray img, Point center, Size axes,
                        double angle, double startAngle, d
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值