OpenCV 4.13.0
开源计算机视觉库 (Open Source Computer Vision)
正在加载...
正在搜索...
未找到匹配项
绘图函数

详细说明

绘图函数适用于任意深度的矩阵/图像。形状的边界可以渲染抗锯齿(目前仅针对8位图像实现)。所有函数都包含参数 color,对于彩色图像,它使用 RGB 值(可以使用 Scalar 构造函数构建),对于灰度图像,它使用亮度值。对于彩色图像,通道顺序通常是 Blue, Green, Red。这也是 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)
 

枚举

enum  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
}
 
enum  cv::LineTypes {
  cv::FILLED = -1 ,
  cv::LINE_4 = 4 ,
  cv::LINE_8 = 8 ,
  cv::LINE_AA = 16
}
 
enum  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)
 绘制一个圆。
 
bool cv::clipLine (Rect imgRect, Point &pt1, Point &pt2)
 
bool cv::clipLine (Size imgSize, Point &pt1, Point &pt2)
 根据图像矩形裁剪直线。
 
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]

枚举类型文档 (Enumeration Type Documentation)

◆ HersheyFonts

#include <opencv2/imgproc.hpp>

只支持 Hershey 字体 https://en.wikipedia.org/wiki/Hershey_fonts 的子集

枚举值 (Enumerator)
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>

线条类型

枚举值 (Enumerator)
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 函数的标记类型集合

枚举值 (Enumerator)
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

向下指向的三角形标记。

函数文档 (Function Documentation)

◆ 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箭头的指向点。
color线条颜色。
thickness线条粗细。
line_type线条类型。参见 LineTypes
移位点坐标中的小数位数。
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>

绘制一个圆。

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

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

◆ 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 图像尺寸,
点 (Point) & pt1,
点 (Point) & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

根据图像矩形裁剪直线。

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

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

◆ clipLine() [3/3]

bool cv::clipLine ( Size2l 图像尺寸,
Point2l & pt1,
Point2l & pt2 )
Python
cv.clipLine(imgRect, pt1, pt2) -> retval, pt1, pt2

#include <opencv2/imgproc.hpp>

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

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

◆ drawContours()

void cv::drawContours ( InputOutputArray 图像,
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]]]]]) -> 图像

#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;
// 第一个命令行参数必须是二值(黑白)图像的文件名
// (black-n-white) image
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:840
int cols
定义 mat.hpp:2204
int rows
行数和列数,当矩阵超过 2 维时为 (-1, -1)
定义 mat.hpp:2204
#define CV_8UC3
定义于 interface.h:90
void imshow(const String &winname, InputArray mat)
在指定窗口中显示图像。
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
创建窗口。
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 命名空间。
参数
图像目标图像。
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十字线标记的位置。
color线条颜色。
markerType您想要使用的特定标记类型,参见 MarkerTypes
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
移位中心坐标和轴值中的小数位数。

◆ 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
移位顶点坐标中的小数位数。

◆ 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
移位顶点坐标中的小数位数。
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;
// 居中文本
Point textOrg((img.cols - textSize.width)/2,
(img.rows + textSize.height)/2);
// 绘制框
rectangle(img, textOrg + Point(0, baseline),
textOrg + Point(textSize.width, -textSize.height),
Scalar(0,0,255));
// ... 先绘制基线
line(img, textOrg + Point(0, thickness),
textOrg + Point(textSize.width, thickness),
Scalar(0, 0, 255));
// 然后放置文本本身
putText(img, text, textOrg, fontFace, fontScale,
Scalar::all(255), thickness, 8);
static Scalar_< double > all(double v0)
用于指定图像或矩形大小的模板类。
定义 types.hpp:335
_Tp height (高度)
高度
定义 types.hpp:363
_Tp width (宽度)
宽度
定义 types.hpp:362
Point2i Point
定义于 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
手写体风格字体
Definition imgproc.hpp:913
参数
text输入文本字符串。
fontFace要使用的字体,参见 HersheyFonts
fontScale字体缩放因子,乘以字体特定的基本大小。
thickness用于渲染文本的线条粗细。详情参见 putText
[out]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线段的第二个点。
color线条颜色。
thickness线条粗细。
lineType线条类型。参见 LineTypes
移位点坐标中的小数位数。

◆ 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
移位顶点坐标中的小数位数。

函数 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
移位点坐标中的小数位数。

◆ 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() and r.br()-Point(1,1) 是对角。