OpenCV 4.12.0
开源计算机视觉
加载中...
搜索中...
无匹配项
绘图函数

详细描述

绘图函数适用于任意深度的矩阵/图像。图形的边界可以进行抗锯齿渲染(目前仅针对8位图像实现)。所有函数都包含一个 `color` 参数,彩色图像使用RGB值(可以通过 Scalar 构造函数构建),灰度图像使用亮度值。对于彩色图像,通道顺序通常是 蓝色、绿色、红色。这是 imshow、imread 和 imwrite 所期望的。因此,如果您使用 Scalar 构造函数构建颜色,它应该看起来像

\[\texttt{Scalar} (blue \_ component, green \_ component, red \_ component[, alpha \_ component])\]

如果您使用自己的图像渲染和I/O函数,可以使用任何通道顺序。绘图函数独立处理每个通道,不依赖于通道顺序,甚至不依赖于所使用的色彩空间。整个图像可以使用 cvtColor 从BGR转换为RGB或转换为不同的色彩空间。

如果绘制的图形部分或完全超出图像,绘图函数会对其进行裁剪。此外,许多绘图函数可以处理以子像素精度指定的像素坐标。这意味着坐标可以作为编码为整数的定点数传递。小数位数由 shift 参数指定,实际点坐标计算为 \(\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\)。此功能在渲染抗锯齿图形时特别有效。

注意
当目标图像是4通道时,这些函数不支持alpha透明度。在这种情况下,color[3] 会被直接复制到重绘的像素。因此,如果您想绘制半透明图形,可以在单独的缓冲区中绘制它们,然后将其与主图像混合。

类  cv::LineIterator
 用于遍历栅格线段上所有像素的类。更多...
 

#define CV_RGB(r, g, b)
 

枚举

枚举  cv::HersheyFonts {
  cv::FONT_HERSHEY_SIMPLEX = 0 ,
  cv::FONT_HERSHEY_PLAIN = 1 ,
  cv::FONT_HERSHEY_DUPLEX = 2 ,
  cv::FONT_HERSHEY_COMPLEX = 3 ,
  cv::FONT_HERSHEY_TRIPLEX = 4 ,
  cv::FONT_HERSHEY_COMPLEX_SMALL = 5 ,
  cv::FONT_HERSHEY_SCRIPT_SIMPLEX = 6 ,
  cv::FONT_HERSHEY_SCRIPT_COMPLEX = 7 ,
  cv::FONT_ITALIC = 16
}
 
枚举  cv::LineTypes {
  cv::FILLED = -1 ,
  cv::LINE_4 = 4 ,
  cv::LINE_8 = 8 ,
  cv::LINE_AA = 16
}
 
枚举  cv::MarkerTypes {
  cv::MARKER_CROSS = 0 ,
  cv::MARKER_TILTED_CROSS = 1 ,
  cv::MARKER_STAR = 2 ,
  cv::MARKER_DIAMOND = 3 ,
  cv::MARKER_SQUARE = 4 ,
  cv::MARKER_TRIANGLE_UP = 5 ,
  cv::MARKER_TRIANGLE_DOWN = 6
}
 

函数

void cv::arrowedLine (InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int line_type=8, int shift=0, double tipLength=0.1)
 绘制从第一个点指向第二个点的箭头线段。
 
void cv::circle (InputOutputArray img, Point center, int radius, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 Draws a circle.
 
bool cv::clipLine (Rect imgRect, Point &pt1, Point &pt2)
 
bool cv::clipLine (Size imgSize, Point &pt1, Point &pt2)
 Clips the line against the image rectangle.
 
bool cv::clipLine (Size2l imgSize, Point2l &pt1, Point2l &pt2)
 
void cv::drawContours (InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar &color, int thickness=1, int lineType=LINE_8, InputArray hierarchy=noArray(), int maxLevel=INT_MAX, Point offset=Point())
 绘制轮廓线或填充轮廓。
 
void cv::drawMarker (InputOutputArray img, Point position, const Scalar &color, int markerType=MARKER_CROSS, int markerSize=20, int thickness=1, int line_type=8)
 在图像中的预定义位置绘制标记。
 
void cv::ellipse (InputOutputArray img, const RotatedRect &box, const Scalar &color, int thickness=1, int lineType=LINE_8)
 
void cv::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)
 绘制简单或粗椭圆弧或填充椭圆扇区。
 
void cv::ellipse2Poly (Point center, Size axes, int angle, int arcStart, int arcEnd, int delta, std::vector< Point > &pts)
 用多边形逼近椭圆弧。
 
void cv::ellipse2Poly (Point2d center, Size2d axes, int angle, int arcStart, int arcEnd, int delta, std::vector< Point2d > &pts)
 
void cv::fillConvexPoly (InputOutputArray img, const Point *pts, int npts, const Scalar &color, int lineType=LINE_8, int shift=0)
 
void cv::fillConvexPoly (InputOutputArray img, InputArray points, const Scalar &color, int lineType=LINE_8, int shift=0)
 填充凸多边形。
 
void cv::fillPoly (InputOutputArray img, const Point **pts, const int *npts, int ncontours, const Scalar &color, int lineType=LINE_8, int shift=0, Point offset=Point())
 
void cv::fillPoly (InputOutputArray img, InputArrayOfArrays pts, const Scalar &color, int lineType=LINE_8, int shift=0, Point offset=Point())
 填充一个或多个多边形所包围的区域。
 
double cv::getFontScaleFromHeight (const int fontFace, const int pixelHeight, const int thickness=1)
 计算用于达到给定像素高度的字体特定大小。
 
Size cv::getTextSize (const String &text, int fontFace, double fontScale, int thickness, int *baseLine)
 计算文本字符串的宽度和高度。
 
void cv::line (InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 绘制连接两点的线段。
 
void cv::polylines (InputOutputArray img, const Point *const *pts, const int *npts, int ncontours, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 
void cv::polylines (InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 绘制多条多边形曲线。
 
void cv::putText (InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
 绘制文本字符串。
 
void cv::rectangle (InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 绘制一个简单、粗或填充的矩形。
 
void cv::rectangle (InputOutputArray img, Rect rec, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 

宏定义文档

◆ CV_RGB

#define CV_RGB ( r,
g,
b )

#include <opencv2/imgproc.hpp>

cv::Scalar((b), (g), (r), 0)
Scalar_< double > Scalar
定义 types.hpp:709

OpenCV的颜色通道顺序是 BGR[A]

枚举类型文档

◆ HersheyFonts

#include <opencv2/imgproc.hpp>

仅支持 Hershey 字体的一部分 https://en.wikipedia.org/wiki/Hershey_fonts

枚举器
FONT_HERSHEY_SIMPLEX 
Python: cv.FONT_HERSHEY_SIMPLEX

正常大小的无衬线字体

FONT_HERSHEY_PLAIN 
Python: cv.FONT_HERSHEY_PLAIN

小尺寸的无衬线字体

FONT_HERSHEY_DUPLEX 
Python: cv.FONT_HERSHEY_DUPLEX

正常大小的无衬线字体(比 FONT_HERSHEY_SIMPLEX 更复杂)

FONT_HERSHEY_COMPLEX 
Python: cv.FONT_HERSHEY_COMPLEX

正常大小的衬线字体

FONT_HERSHEY_TRIPLEX 
Python: cv.FONT_HERSHEY_TRIPLEX

正常大小的衬线字体(比 FONT_HERSHEY_COMPLEX 更复杂)

FONT_HERSHEY_COMPLEX_SMALL 
Python: cv.FONT_HERSHEY_COMPLEX_SMALL

FONT_HERSHEY_COMPLEX 的缩小版

FONT_HERSHEY_SCRIPT_SIMPLEX 
Python: cv.FONT_HERSHEY_SCRIPT_SIMPLEX

手写风格字体

FONT_HERSHEY_SCRIPT_COMPLEX 
Python: cv.FONT_HERSHEY_SCRIPT_COMPLEX

FONT_HERSHEY_SCRIPT_SIMPLEX 的更复杂变体

FONT_ITALIC 
Python: cv.FONT_ITALIC

斜体字体标志

◆ LineTypes

#include <opencv2/imgproc.hpp>

线条类型

枚举器
FILLED 
Python: cv.FILLED
LINE_4 
Python: cv.LINE_4

4连通线

LINE_8 
Python: cv.LINE_8

8 连接线

LINE_AA 
Python: cv.LINE_AA

抗锯齿线

◆ MarkerTypes

#include <opencv2/imgproc.hpp>

用于 cv::drawMarker 函数的标记类型集合

枚举器
MARKER_CROSS 
Python: cv.MARKER_CROSS

十字标记形状。

MARKER_TILTED_CROSS 
Python: cv.MARKER_TILTED_CROSS

45度倾斜的十字标记形状。

MARKER_STAR 
Python: cv.MARKER_STAR

星形标记形状,十字形和倾斜十字形的组合。

MARKER_DIAMOND 
Python: cv.MARKER_DIAMOND

菱形标记形状。

MARKER_SQUARE 
Python: cv.MARKER_SQUARE

一个正方形标记形状。

MARKER_TRIANGLE_UP 
Python: cv.MARKER_TRIANGLE_UP

向上指向的三角形标记形状。

MARKER_TRIANGLE_DOWN 
Python: cv.MARKER_TRIANGLE_DOWN

向下指向的三角形标记形状。

函数文档

◆ arrowedLine()

void cv::arrowedLine ( InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int line_type = 8,
int shift = 0,
double tipLength = 0.1 )
Python
cv.arrowedLine(img, pt1, pt2, color[, thickness[, line_type[, shift[, tipLength]]]]) -> img

#include <opencv2/imgproc.hpp>

绘制从第一个点指向第二个点的箭头线段。

函数 cv::arrowedLine 在图像中绘制从 pt1 到 pt2 的箭头。另请参见 line

参数
img图像。
pt1箭头的起点。
pt2箭头的指向点。
coloropencv2/ximgproc/fast_line_detector.hpp
thicknessLine thickness.
line_type线条类型。参见 LineTypes
移位 (shift)点坐标中的小数位数。
tipLength箭头尖端相对于箭身长度的比例。

◆ circle()

void cv::circle ( InputOutputArray img,
Point center,
int radius,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.circle(img, center, radius, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

Draws a circle.

函数 cv::circle 绘制一个简单或填充的圆,具有给定的中心和半径。

参数
img绘制圆的图像。
center圆的中心。
radius圆的半径。
color圆的颜色。
thickness圆轮廓的粗细,如果为正。负值(例如 FILLED)表示将绘制一个填充圆。
lineType圆边界的类型。参见 LineTypes
移位 (shift)中心坐标和半径值中的小数位数。

◆ clipLine() [1/3]

bool cv::clipLine ( Rect imgRect,
Point & pt1,
Point & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

这是一个重载成员函数,为方便起见而提供。它与上述函数的区别仅在于所接受的参数。

参数
imgRect图像矩形。
pt1线的第一个点。
pt2线的第二个点。

◆ clipLine() [2/3]

bool cv::clipLine ( Size imgSize,
Point & pt1,
Point & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

Clips the line against the image rectangle.

函数 cv::clipLine 计算完全位于指定矩形内的线段部分。如果线段完全在矩形外部,则返回 false。否则,返回 true。

参数
imgSize图像尺寸。图像矩形为 Rect(0, 0, imgSize.width, imgSize.height)。
pt1线的第一个点。
pt2线的第二个点。

◆ clipLine() [3/3]

bool cv::clipLine ( Size2l imgSize,
Point2l & pt1,
Point2l & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

这是一个重载成员函数,为方便起见而提供。它与上述函数的区别仅在于所接受的参数。

参数
imgSize图像尺寸。图像矩形为 Rect(0, 0, imgSize.width, imgSize.height)。
pt1线的第一个点。
pt2线的第二个点。

◆ drawContours()

void cv::drawContours ( InputOutputArray image,
InputArrayOfArrays contours,
int contourIdx,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
InputArray hierarchy = noArray(),
int maxLevel = INT_MAX,
Point offset = Point() )
Python
cv.drawContours(image, contours, contourIdx, color[, thickness[, lineType[, hierarchy[, maxLevel[, offset]]]]]) -> image

#include <opencv2/imgproc.hpp>

绘制轮廓线或填充轮廓。

如果 \(\texttt{thickness} \ge 0\) 则函数在图像中绘制轮廓线,如果 \(\texttt{thickness}<0\) 则填充轮廓所限定的区域。下面的示例展示了如何从二值图像中检索连通分量并对其进行标记:

using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
Mat src;
// 第一个命令行参数必须是二值图像的文件名
// (黑白)图像
if( argc != 2 || !(src=imread(argv[1], IMREAD_GRAYSCALE)).data)
return -1;
Mat dst = Mat::zeros(src.rows, src.cols, CV_8UC3);
src = src > 1;
namedWindow( "Source", 1 );
imshow( "Source", src );
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( src, contours, hierarchy,
RETR_CCOMP, CHAIN_APPROX_SIMPLE );
// 迭代所有顶层轮廓,
// 用其自己的随机颜色绘制每个连接的组件
int idx = 0;
for( ; idx >= 0; idx = hierarchy[idx][0] )
{
Scalar color( rand()&255, rand()&255, rand()&255 );
drawContours( dst, contours, idx, color, FILLED, 8, hierarchy );
}
namedWindow( "Components", 1 );
imshow( "Components", dst );
waitKey(0);
}
n 维密集数组类
定义 mat.hpp:830
int cols
定义 mat.hpp:2165
int rows
当矩阵维度大于2时,行数和列数,或(-1, -1)
定义 mat.hpp:2165
CV_8UC3
#define CV_8UC3
void imshow(const String &winname, InputArray mat)
在指定窗口中显示图像。
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
创建窗口。
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
从文件加载图像。
void drawContours(InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar &color, int thickness=1, int lineType=LINE_8, InputArray hierarchy=noArray(), int maxLevel=INT_MAX, Point offset=Point())
绘制轮廓线或填充轮廓。
void findContours(InputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())
在二值图像中查找轮廓。
int main(int argc, char *argv[])
定义 highgui_qt.cpp:3
定义 core.hpp:107
STL 命名空间。
参数
image目标图像。
contours所有输入轮廓。每个轮廓都存储为一个点向量。
contourIdx指示要绘制的轮廓的参数。如果为负,则绘制所有轮廓。
color轮廓的颜色。
thickness绘制轮廓线的粗细。如果为负(例如,thickness=FILLED),则绘制轮廓内部。
lineType线条连接性。参见 LineTypes
hierarchy可选的层次结构信息。仅当您只想绘制部分轮廓时才需要(参见 maxLevel)。
maxLevel绘制轮廓的最大级别。如果为0,则仅绘制指定的轮廓。如果为1,则函数绘制轮廓及其所有嵌套轮廓。如果为2,则函数绘制轮廓、所有嵌套轮廓、所有嵌套的嵌套轮廓,依此类推。此参数仅在存在层次结构时才考虑。
offset可选的轮廓偏移参数。将所有绘制的轮廓按指定的 \(\texttt{offset}=(dx,dy)\) 偏移。
注意
当 thickness=FILLED 时,即使没有提供层次结构数据,该函数也能正确处理带孔的连通分量。这是通过使用奇偶规则一起分析所有轮廓来完成的。如果您有一个单独检索的轮廓的联合集合,这可能会产生不正确的结果。为了解决这个问题,您需要为每个轮廓子组分别调用 drawContours,或使用 contourIdx 参数遍历集合。

◆ drawMarker()

void cv::drawMarker ( InputOutputArray img,
Point position,
const Scalar & color,
int markerType = MARKER_CROSS,
int markerSize = 20,
int thickness = 1,
int line_type = 8 )
Python
cv.drawMarker(img, position, color[, markerType[, markerSize[, thickness[, line_type]]]]) -> img

#include <opencv2/imgproc.hpp>

在图像中的预定义位置绘制标记。

函数 cv::drawMarker 在图像中的给定位置绘制标记。目前支持几种标记类型,详见 MarkerTypes

参数
img图像。
position十字标记的定位点。
coloropencv2/ximgproc/fast_line_detector.hpp
markerType你想要使用的标记的具体类型,参见 MarkerTypes
thicknessLine thickness.
line_type线的类型,参见 LineTypes
markerSize标记轴的长度 [默认 = 20 像素]

◆ ellipse() [1/2]

void cv::ellipse ( InputOutputArray img,
const RotatedRect & box,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8 )
Python
cv.ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[, lineType[, shift]]]) -> img
cv.ellipse(img, box, color[, thickness[, lineType]]) -> img

#include <opencv2/imgproc.hpp>

这是一个重载成员函数,为方便起见而提供。它与上述函数的区别仅在于所接受的参数。

参数
img图像。
box通过 RotatedRect 的另一种椭圆表示形式。这意味着此函数绘制一个内切于旋转矩形的椭圆。
color椭圆颜色。
thickness椭圆弧轮廓的粗细,如果为正。否则,表示将绘制一个填充的椭圆扇区。
lineType椭圆边界的类型。参见 LineTypes

◆ ellipse() [2/2]

void cv::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 )
Python
cv.ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[, lineType[, shift]]]) -> img
cv.ellipse(img, box, color[, thickness[, lineType]]) -> img

#include <opencv2/imgproc.hpp>

绘制简单或粗椭圆弧或填充椭圆扇区。

具有更多参数的函数 cv::ellipse 绘制椭圆轮廓、填充椭圆、椭圆弧或填充椭圆扇区。绘图代码使用一般参数形式。分段线性曲线用于近似椭圆弧边界。如果您需要对椭圆渲染进行更多控制,可以使用 ellipse2Poly 获取曲线,然后使用 polylines 渲染或使用 fillPoly 填充。如果您使用函数的第一个变体并想要绘制整个椭圆而不是弧,请传递 startAngle=0endAngle=360。如果 startAngle 大于 endAngle,它们将被交换。下图解释了绘制蓝色弧线的参数含义。

椭圆弧的参数
参数
img图像。
center椭圆中心。
axes椭圆主轴尺寸的一半。
angle椭圆旋转角度(以度为单位)。
startAngle椭圆弧的起始角度(以度为单位)。
endAngle椭圆弧的结束角度(以度为单位)。
color椭圆颜色。
thickness椭圆弧轮廓的粗细,如果为正。否则,表示将绘制一个填充的椭圆扇区。
lineType椭圆边界的类型。参见 LineTypes
移位 (shift)中心坐标和轴值中的小数位数。

◆ ellipse2Poly() [1/2]

void cv::ellipse2Poly ( Point center,
Size axes,
int angle,
int arcStart,
int arcEnd,
int delta,
std::vector< Point > & pts )
Python
cv.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta) -> pts

#include <opencv2/imgproc.hpp>

用多边形逼近椭圆弧。

函数 ellipse2Poly 计算近似指定椭圆弧的折线顶点。它被 ellipse 使用。如果 arcStart 大于 arcEnd,它们将被交换。

参数
center弧的中心。
axes椭圆主轴尺寸的一半。详见 ellipse
angle椭圆的旋转角度(以度为单位)。详见 ellipse
arcStart椭圆弧的起始角度(以度为单位)。
arcEnd椭圆弧的结束角度(以度为单位)。
delta连续折线顶点之间的角度。它定义了近似精度。
pts折线顶点的输出向量。

◆ ellipse2Poly() [2/2]

void cv::ellipse2Poly ( Point2d center,
Size2d axes,
int angle,
int arcStart,
int arcEnd,
int delta,
std::vector< Point2d > & pts )
Python
cv.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta) -> pts

#include <opencv2/imgproc.hpp>

这是一个重载成员函数,为方便起见而提供。它与上述函数的区别仅在于所接受的参数。

参数
center弧的中心。
axes椭圆主轴尺寸的一半。详见 ellipse
angle椭圆的旋转角度(以度为单位)。详见 ellipse
arcStart椭圆弧的起始角度(以度为单位)。
arcEnd椭圆弧的结束角度(以度为单位)。
delta连续折线顶点之间的角度。它定义了近似精度。
pts折线顶点的输出向量。

◆ fillConvexPoly() [1/2]

void cv::fillConvexPoly ( InputOutputArray img,
const Point * pts,
int npts,
const Scalar & color,
int lineType = LINE_8,
int shift = 0 )
Python
cv.fillConvexPoly(img, points, color[, lineType[, shift]]) -> img

#include <opencv2/imgproc.hpp>

这是一个重载成员函数,为方便起见而提供。它与上述函数的区别仅在于所接受的参数。

◆ fillConvexPoly() [2/2]

void cv::fillConvexPoly ( InputOutputArray img,
InputArray points,
const Scalar & color,
int lineType = LINE_8,
int shift = 0 )
Python
cv.fillConvexPoly(img, points, color[, lineType[, shift]]) -> img

#include <opencv2/imgproc.hpp>

填充凸多边形。

函数 cv::fillConvexPoly 绘制一个填充的凸多边形。此函数比函数 fillPoly 快得多。它不仅可以填充凸多边形,还可以填充任何没有自相交的单调多边形,即其轮廓最多与每条水平线(扫描线)相交两次的多边形(尽管其最顶部和/或最底部边缘可以是水平的)。

参数
img图像。
points多边形顶点。
color多边形颜色。
lineType多边形边界的类型。参见 LineTypes
移位 (shift)顶点坐标中的小数位数。

◆ fillPoly() [1/2]

void cv::fillPoly ( InputOutputArray img,
const Point ** pts,
const int * npts,
int ncontours,
const Scalar & color,
int lineType = LINE_8,
int shift = 0,
Point offset = Point() )
Python
cv.fillPoly(img, pts, color[, lineType[, shift[, offset]]]) -> img

#include <opencv2/imgproc.hpp>

这是一个重载成员函数,为方便起见而提供。它与上述函数的区别仅在于所接受的参数。

◆ fillPoly() [2/2]

void cv::fillPoly ( InputOutputArray img,
InputArrayOfArrays pts,
const Scalar & color,
int lineType = LINE_8,
int shift = 0,
Point offset = Point() )
Python
cv.fillPoly(img, pts, color[, lineType[, shift[, offset]]]) -> img

#include <opencv2/imgproc.hpp>

填充一个或多个多边形所包围的区域。

函数 cv::fillPoly 填充由多个多边形轮廓围成的区域。该函数可以填充复杂的区域,例如带有孔洞的区域、具有自相交的轮廓(某些部分)等等。

参数
img图像。
pts多边形数组,其中每个多边形表示为点数组。
color多边形颜色。
lineType多边形边界的类型。参见 LineTypes
移位 (shift)顶点坐标中的小数位数。
offset轮廓所有点的可选偏移量。

◆ getFontScaleFromHeight()

double cv::getFontScaleFromHeight ( const int fontFace,
const int pixelHeight,
const int thickness = 1 )
Python
cv.getFontScaleFromHeight(fontFace, pixelHeight[, thickness]) -> retval

#include <opencv2/imgproc.hpp>

计算用于达到给定像素高度的字体特定大小。

参数
fontFace要使用的字体,参见 cv::HersheyFonts
pixelHeight用于计算 fontScale 的像素高度
thickness用于渲染文本的线条粗细。详见 putText。
返回
用于 cv::putText 的字体大小
另请参见
cv::putText

◆ getTextSize()

Size cv::getTextSize ( const String & text,
int fontFace,
double fontScale,
int thickness,
int * baseLine )
Python
cv.getTextSize(text, fontFace, fontScale, thickness) -> retval, baseLine

#include <opencv2/imgproc.hpp>

计算文本字符串的宽度和高度。

函数 cv::getTextSize 计算并返回包含指定文本的框的大小。也就是说,以下代码渲染文本、围绕文本的紧密框以及基线:

String text = "Funny text inside the box";
double fontScale = 2;
int thickness = 3;
Mat img(600, 800, CV_8UC3, Scalar::all(0));
int baseline=0;
Size textSize = getTextSize(text, fontFace,
fontScale, thickness, &baseline);
baseline += thickness;
// center the text
Point textOrg((img.cols - textSize.width)/2,
(img.rows + textSize.height)/2);
// draw the box
rectangle(img, textOrg + Point(0, baseline),
textOrg + Point(textSize.width, -textSize.height),
Scalar(0,0,255));
// ... and the baseline first
line(img, textOrg + Point(0, thickness),
textOrg + Point(textSize.width, thickness),
Scalar(0, 0, 255));
// then put the text itself
putText(img, text, textOrg, fontFace, fontScale,
Scalar::all(255), thickness, 8);
static Scalar_< double > all(double v0)
用于指定图像或矩形大小的模板类。
Definition types.hpp:335
_Tp height
高度
Definition types.hpp:363
_Tp width
宽度
Definition types.hpp:362
typedef Point_< double > 
Point2i Point
Definition types.hpp:209
std::string String
定义 cvstd.hpp:151
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
绘制一个简单、粗或填充的矩形。
Size getTextSize(const String &text, int fontFace, double fontScale, int thickness, int *baseLine)
计算文本字符串的宽度和高度。
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
绘制文本字符串。
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
绘制连接两点的线段。
@ FONT_HERSHEY_SCRIPT_SIMPLEX
手写风格字体
定义 imgproc.hpp:909
参数
text输入文本字符串。
fontFace要使用的字体,参见 HersheyFonts
fontScale字体缩放因子,乘以字体特有的基本大小。
thickness用于渲染文本的线条粗细。详见 putText
[输出]baseLine基线相对于文本最底点的 y 坐标。
返回
包含指定文本的框的大小。
另请参见
putText

◆ line()

void cv::line ( InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.line(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

绘制连接两点的线段。

函数 line 在图像中绘制 pt1 和 pt2 点之间的线段。线段被图像边界裁剪。对于具有整数坐标的非抗锯齿线条,使用 8 连通或 4 连通的 Bresenham 算法。粗线以圆角端点绘制。抗锯齿线条使用高斯滤波绘制。

参数
img图像。
pt1线段的第一个点。
pt2线段的第二个点。
coloropencv2/ximgproc/fast_line_detector.hpp
thicknessLine thickness.
lineType线的类型。参见 LineTypes
移位 (shift)点坐标中的小数位数。

◆ polylines() [1/2]

void cv::polylines ( InputOutputArray img,
const Point *const * pts,
const int * npts,
int ncontours,
bool isClosed,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

这是一个重载成员函数,为方便起见而提供。它与上述函数的区别仅在于所接受的参数。

◆ polylines() [2/2]

void cv::polylines ( InputOutputArray img,
InputArrayOfArrays pts,
bool isClosed,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.polylines(img, pts, isClosed, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

绘制多条多边形曲线。

参数
img图像。
pts多边形曲线数组。
isClosed指示绘制的多段线是否闭合的标志。如果闭合,函数将从每条曲线的最后一个顶点到其第一个顶点绘制一条线。
color多段线颜色。
thickness多段线边缘的粗细。
lineType线段的类型。参见 LineTypes
移位 (shift)顶点坐标中的小数位数。

函数 cv::polylines 绘制一个或多个多边形曲线。

◆ putText()

void cv::putText ( InputOutputArray img,
const String & text,
Point org,
int fontFace,
double fontScale,
Scalar color,
int thickness = 1,
int lineType = LINE_8,
bool bottomLeftOrigin = false )
Python
cv.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]]) -> img

#include <opencv2/imgproc.hpp>

绘制文本字符串。

函数 cv::putText 在图像中渲染指定的文本字符串。无法使用指定字体渲染的符号将替换为问号。有关文本渲染代码示例,请参见 getTextSize

fontScale 参数是一个缩放因子,它乘以基本字体大小

  • 当 scale > 1 时,文本被放大。
  • 当 0 < scale < 1 时,文本被缩小。
  • 当 scale < 0 时,文本被镜像或反转。
参数
img图像。
text要绘制的文本字符串。
org图像中文本字符串的左下角。
fontFace字体类型,参见 HersheyFonts
fontScale字体缩放因子,乘以字体特有的基本大小。
color文本颜色。
thickness用于绘制文本的线条粗细。
lineType线条类型。参见 LineTypes
bottomLeftOrigin当为 true 时,图像数据原点在左下角。否则,在左上角。
示例
samples/cpp/fitellipse.cpp.

◆ rectangle() [1/2]

void cv::rectangle ( InputOutputArray img,
Point pt1,
Point pt2,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) -> img
cv.rectangle(img, rec, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

绘制一个简单、粗或填充的矩形。

函数 cv::rectangle 绘制矩形轮廓或填充矩形,其两个相对角为 pt1 和 pt2。

参数
img图像。
pt1矩形的顶点。
pt2与 pt1 相对的矩形顶点。
color矩形颜色或亮度(灰度图像)。
thickness构成矩形的线条粗细。负值(例如 FILLED)表示函数需要绘制一个填充矩形。
lineType线条类型。参见 LineTypes
移位 (shift)点坐标中的小数位数。

◆ rectangle() [2/2]

void cv::rectangle ( InputOutputArray img,
Rect rec,
const Scalar & color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0 )
Python
cv.rectangle(img, pt1, pt2, color[, thickness[, lineType[, shift]]]) -> img
cv.rectangle(img, rec, color[, thickness[, lineType[, shift]]]) -> img

#include <opencv2/imgproc.hpp>

这是一个重载成员函数,为方便起见而提供。它与上述函数的区别仅在于所接受的参数。

使用 rec 参数作为绘制矩形的替代规范:r.tl()r.br()-Point(1,1) 是相对角