OpenCV 5.0.0-pre
Open Source Computer Vision
Loading...
Searching...
No Matches
Drawing Functions

Detailed Description

Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be rendered with antialiasing (implemented only for 8-bit images for now). All the functions include the parameter color that uses an RGB value (that may be constructed with the Scalar constructor ) for color images and brightness for grayscale images. For color images, the channel ordering is normally Blue, Green, Red. This is what imshow, imread, and imwrite expect. So, if you form a color using the Scalar constructor, it should look like:

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

If you are using your own image rendering and I/O functions, you can use any channel ordering. The drawing functions process each channel independently and do not depend on the channel order or even on the used color space. The whole image can be converted from BGR to RGB or to a different color space using cvtColor .

If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also, many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means that the coordinates can be passed as fixed-point numbers encoded as integers. The number of fractional bits is specified by the shift parameter and the real point coordinates are calculated as \(\texttt{Point}(x,y)\rightarrow\texttt{Point2f}(x*2^{-shift},y*2^{-shift})\) . This feature is especially effective when rendering antialiased shapes.

Note
The functions do not support alpha-transparency when the target image is 4-channel. In this case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main image.

Classes

class  cv::FontFace
 Wrapper on top of a truetype/opentype/etc font, i.e. Freetype's FT_Face. More...
 
class  cv::LineIterator
 Class for iterating over all pixels on a raster line segment. More...
 

Macros

#define CV_RGB(r, g, b)
 

Enumerations

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
}
 
enum  cv::PutTextFlags {
  cv::PUT_TEXT_ALIGN_LEFT =0 ,
  cv::PUT_TEXT_ALIGN_CENTER =1 ,
  cv::PUT_TEXT_ALIGN_RIGHT =2 ,
  cv::PUT_TEXT_ALIGN_MASK =3 ,
  cv::PUT_TEXT_ORIGIN_TL =0 ,
  cv::PUT_TEXT_ORIGIN_BL =32 ,
  cv::PUT_TEXT_WRAP =128
}
 Defines various put text flags. More...
 

Functions

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)
 Draws an arrow segment pointing from the first point to the second one.
 
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())
 Draws contours outlines or filled contours.
 
void cv::drawMarker (InputOutputArray img, Point position, const Scalar &color, int markerType=MARKER_CROSS, int markerSize=20, int thickness=1, int line_type=8)
 Draws a marker on a predefined position in an image.
 
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)
 Draws a simple or thick elliptic arc or fills an ellipse sector.
 
void cv::ellipse2Poly (Point center, Size axes, int angle, int arcStart, int arcEnd, int delta, std::vector< Point > &pts)
 Approximates an elliptic arc with a polyline.
 
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)
 Fills a convex polygon.
 
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())
 Fills the area bounded by one or more polygons.
 
double cv::getFontScaleFromHeight (const int fontFace, const int pixelHeight, const int thickness=1)
 Calculates the font-specific size to use to achieve a given height in pixels.
 
Size cv::getTextSize (const String &text, int fontFace, double fontScale, int thickness, int *baseLine)
 Calculates the width and height of a text string.
 
Rect cv::getTextSize (Size imgsize, const String &text, Point org, FontFace &fface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range())
 Calculates the bounding rect for the text.
 
void cv::line (InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 Draws a line segment connecting two points.
 
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)
 Draws several polygonal curves.
 
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)
 Draws a text string.
 
Point cv::putText (InputOutputArray img, const String &text, Point org, Scalar color, FontFace &fface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range())
 Draws a text string using specified font.
 
void cv::rectangle (InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 Draws a simple, thick, or filled up-right rectangle.
 
void cv::rectangle (InputOutputArray img, Rect rec, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
 

Macro Definition Documentation

◆ CV_RGB

#define CV_RGB ( r,
g,
b )

#include <opencv2/imgproc.hpp>

Value:
cv::Scalar((b), (g), (r), 0)
Scalar_< double > Scalar
Definition types.hpp:712

OpenCV color channel order is BGR[A]

Enumeration Type Documentation

◆ HersheyFonts

#include <opencv2/imgproc.hpp>

Only a subset of Hershey fonts https://en.wikipedia.org/wiki/Hershey_fonts are supported

Enumerator
FONT_HERSHEY_SIMPLEX 
Python: cv.FONT_HERSHEY_SIMPLEX

normal size sans-serif font

FONT_HERSHEY_PLAIN 
Python: cv.FONT_HERSHEY_PLAIN

small size sans-serif font

FONT_HERSHEY_DUPLEX 
Python: cv.FONT_HERSHEY_DUPLEX

normal size sans-serif font (more complex than FONT_HERSHEY_SIMPLEX)

FONT_HERSHEY_COMPLEX 
Python: cv.FONT_HERSHEY_COMPLEX

normal size serif font

FONT_HERSHEY_TRIPLEX 
Python: cv.FONT_HERSHEY_TRIPLEX

normal size serif font (more complex than FONT_HERSHEY_COMPLEX)

FONT_HERSHEY_COMPLEX_SMALL 
Python: cv.FONT_HERSHEY_COMPLEX_SMALL

smaller version of FONT_HERSHEY_COMPLEX

FONT_HERSHEY_SCRIPT_SIMPLEX 
Python: cv.FONT_HERSHEY_SCRIPT_SIMPLEX

hand-writing style font

FONT_HERSHEY_SCRIPT_COMPLEX 
Python: cv.FONT_HERSHEY_SCRIPT_COMPLEX

more complex variant of FONT_HERSHEY_SCRIPT_SIMPLEX

FONT_ITALIC 
Python: cv.FONT_ITALIC

flag for italic font

◆ LineTypes

#include <opencv2/imgproc.hpp>

types of line

Enumerator
FILLED 
Python: cv.FILLED
LINE_4 
Python: cv.LINE_4

4-connected line

LINE_8 
Python: cv.LINE_8

8-connected line

LINE_AA 
Python: cv.LINE_AA

antialiased line

◆ MarkerTypes

#include <opencv2/imgproc.hpp>

Possible set of marker types used for the cv::drawMarker function

Enumerator
MARKER_CROSS 
Python: cv.MARKER_CROSS

A crosshair marker shape.

MARKER_TILTED_CROSS 
Python: cv.MARKER_TILTED_CROSS

A 45 degree tilted crosshair marker shape.

MARKER_STAR 
Python: cv.MARKER_STAR

A star marker shape, combination of cross and tilted cross.

MARKER_DIAMOND 
Python: cv.MARKER_DIAMOND

A diamond marker shape.

MARKER_SQUARE 
Python: cv.MARKER_SQUARE

A square marker shape.

MARKER_TRIANGLE_UP 
Python: cv.MARKER_TRIANGLE_UP

An upwards pointing triangle marker shape.

MARKER_TRIANGLE_DOWN 
Python: cv.MARKER_TRIANGLE_DOWN

A downwards pointing triangle marker shape.

◆ PutTextFlags

#include <opencv2/imgproc.hpp>

Defines various put text flags.

Enumerator
PUT_TEXT_ALIGN_LEFT 
Python: cv.PUT_TEXT_ALIGN_LEFT
PUT_TEXT_ALIGN_CENTER 
Python: cv.PUT_TEXT_ALIGN_CENTER
PUT_TEXT_ALIGN_RIGHT 
Python: cv.PUT_TEXT_ALIGN_RIGHT
PUT_TEXT_ALIGN_MASK 
Python: cv.PUT_TEXT_ALIGN_MASK
PUT_TEXT_ORIGIN_TL 
Python: cv.PUT_TEXT_ORIGIN_TL
PUT_TEXT_ORIGIN_BL 
Python: cv.PUT_TEXT_ORIGIN_BL
PUT_TEXT_WRAP 
Python: cv.PUT_TEXT_WRAP

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>

Draws an arrow segment pointing from the first point to the second one.

The function cv::arrowedLine draws an arrow between pt1 and pt2 points in the image. See also line.

Parameters
imgImage.
pt1The point the arrow starts from.
pt2The point the arrow points to.
colorLine color.
thicknessLine thickness.
line_typeType of the line. See LineTypes
shiftNumber of fractional bits in the point coordinates.
tipLengthThe length of the arrow tip in relation to the arrow length

◆ 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.

The function cv::circle draws a simple or filled circle with a given center and radius.

Parameters
imgImage where the circle is drawn.
centerCenter of the circle.
radiusRadius of the circle.
colorCircle color.
thicknessThickness of the circle outline, if positive. Negative values, like FILLED, mean that a filled circle is to be drawn.
lineTypeType of the circle boundary. See LineTypes
shiftNumber of fractional bits in the coordinates of the center and in the radius value.

◆ 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>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
imgRectImage rectangle.
pt1First line point.
pt2Second line point.

◆ 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.

The function cv::clipLine calculates a part of the line segment that is entirely within the specified rectangle. It returns false if the line segment is completely outside the rectangle. Otherwise, it returns true .

Parameters
imgSizeImage size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) .
pt1First line point.
pt2Second line point.

◆ 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>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
imgSizeImage size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) .
pt1First line point.
pt2Second line point.

◆ 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>

Draws contours outlines or filled contours.

The function draws contour outlines in the image if \(\texttt{thickness} \ge 0\) or fills the area bounded by the contours if \(\texttt{thickness}<0\) . The example below shows how to retrieve connected components from the binary image and label them: :

using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
Mat src;
// the first command-line parameter must be a filename of the binary
// (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 );
// iterate through all the top-level contours,
// draw each connected component with its own random color
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-dimensional dense array class
Definition mat.hpp:951
int cols
Definition mat.hpp:2425
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
Definition mat.hpp:2425
#define CV_8UC3
Definition interface.h:79
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
Loads an image from a file.
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())
Draws contours outlines or filled contours.
void findContours(InputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())
Finds contours in a binary image.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
Definition core.hpp:107
STL namespace.
Parameters
imageDestination image.
contoursAll the input contours. Each contour is stored as a point vector.
contourIdxParameter indicating a contour to draw. If it is negative, all the contours are drawn.
colorColor of the contours.
thicknessThickness of lines the contours are drawn with. If it is negative (for example, thickness=FILLED ), the contour interiors are drawn.
lineTypeLine connectivity. See LineTypes
hierarchyOptional information about hierarchy. It is only needed if you want to draw only some of the contours (see maxLevel ).
maxLevelMaximal level for drawn contours. If it is 0, only the specified contour is drawn. If it is 1, the function draws the contour(s) and all the nested contours. If it is 2, the function draws the contours, all the nested contours, all the nested-to-nested contours, and so on. This parameter is only taken into account when there is hierarchy available.
offsetOptional contour shift parameter. Shift all the drawn contours by the specified \(\texttt{offset}=(dx,dy)\) .
Note
When thickness=FILLED, the function is designed to handle connected components with holes correctly even when no hierarchy data is provided. This is done by analyzing all the outlines together using even-odd rule. This may give incorrect results if you have a joint collection of separately retrieved contours. In order to solve this problem, you need to call drawContours separately for each sub-group of contours, or iterate over the collection using contourIdx parameter.

◆ 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>

Draws a marker on a predefined position in an image.

The function cv::drawMarker draws a marker on a given position in the image. For the moment several marker types are supported, see MarkerTypes for more information.

Parameters
imgImage.
positionThe point where the crosshair is positioned.
colorLine color.
markerTypeThe specific type of marker you want to use, see MarkerTypes
thicknessLine thickness.
line_typeType of the line, See LineTypes
markerSizeThe length of the marker axis [default = 20 pixels]

◆ 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>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
imgImage.
boxAlternative ellipse representation via RotatedRect. This means that the function draws an ellipse inscribed in the rotated rectangle.
colorEllipse color.
thicknessThickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.
lineTypeType of the ellipse boundary. See 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>

Draws a simple or thick elliptic arc or fills an ellipse sector.

The function cv::ellipse with more parameters draws an ellipse outline, a filled ellipse, an elliptic arc, or a filled ellipse sector. The drawing code uses general parametric form. A piecewise-linear curve is used to approximate the elliptic arc boundary. If you need more control of the ellipse rendering, you can retrieve the curve using ellipse2Poly and then render it with polylines or fill it with fillPoly. If you use the first variant of the function and want to draw the whole ellipse, not an arc, pass startAngle=0 and endAngle=360. If startAngle is greater than endAngle, they are swapped. The figure below explains the meaning of the parameters to draw the blue arc.

Parameters of Elliptic Arc
Parameters
imgImage.
centerCenter of the ellipse.
axesHalf of the size of the ellipse main axes.
angleEllipse rotation angle in degrees.
startAngleStarting angle of the elliptic arc in degrees.
endAngleEnding angle of the elliptic arc in degrees.
colorEllipse color.
thicknessThickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.
lineTypeType of the ellipse boundary. See LineTypes
shiftNumber of fractional bits in the coordinates of the center and values of axes.

◆ 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>

Approximates an elliptic arc with a polyline.

The function ellipse2Poly computes the vertices of a polyline that approximates the specified elliptic arc. It is used by ellipse. If arcStart is greater than arcEnd, they are swapped.

Parameters
centerCenter of the arc.
axesHalf of the size of the ellipse main axes. See ellipse for details.
angleRotation angle of the ellipse in degrees. See ellipse for details.
arcStartStarting angle of the elliptic arc in degrees.
arcEndEnding angle of the elliptic arc in degrees.
deltaAngle between the subsequent polyline vertices. It defines the approximation accuracy.
ptsOutput vector of polyline vertices.

◆ 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>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
centerCenter of the arc.
axesHalf of the size of the ellipse main axes. See ellipse for details.
angleRotation angle of the ellipse in degrees. See ellipse for details.
arcStartStarting angle of the elliptic arc in degrees.
arcEndEnding angle of the elliptic arc in degrees.
deltaAngle between the subsequent polyline vertices. It defines the approximation accuracy.
ptsOutput vector of polyline vertices.

◆ 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>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ 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>

Fills a convex polygon.

The function cv::fillConvexPoly draws a filled convex polygon. This function is much faster than the function fillPoly . It can fill not only convex polygons but any monotonic polygon without self-intersections, that is, a polygon whose contour intersects every horizontal line (scan line) twice at the most (though, its top-most and/or the bottom edge could be horizontal).

Parameters
imgImage.
pointsPolygon vertices.
colorPolygon color.
lineTypeType of the polygon boundaries. See LineTypes
shiftNumber of fractional bits in the vertex coordinates.

◆ 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>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ 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>

Fills the area bounded by one or more polygons.

The function cv::fillPoly fills an area bounded by several polygonal contours. The function can fill complex areas, for example, areas with holes, contours with self-intersections (some of their parts), and so forth.

Parameters
imgImage.
ptsArray of polygons where each polygon is represented as an array of points.
colorPolygon color.
lineTypeType of the polygon boundaries. See LineTypes
shiftNumber of fractional bits in the vertex coordinates.
offsetOptional offset of all points of the contours.

◆ 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>

Calculates the font-specific size to use to achieve a given height in pixels.

Parameters
fontFaceFont to use, see cv::HersheyFonts.
pixelHeightPixel height to compute the fontScale for
thicknessThickness of lines used to render the text.See putText for details.
Returns
The fontSize to use for cv::putText
See also
cv::putText

◆ getTextSize() [1/2]

Size cv::getTextSize ( const String & text,
int fontFace,
double fontScale,
int thickness,
int * baseLine )
Python:
cv.getTextSize(text, fontFace, fontScale, thickness) -> retval, baseLine
cv.getTextSize(imgsize, text, org, fface, size[, weight[, flags[, wrap]]]) -> retval

#include <opencv2/imgproc.hpp>

Calculates the width and height of a text string.

The function cv::getTextSize calculates and returns the size of a box that contains the specified text. That is, the following code renders some text, the tight box surrounding it, and the baseline: :

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)
Template class for specifying the size of an image or rectangle.
Definition types.hpp:338
_Tp height
the height
Definition types.hpp:366
_Tp width
the width
Definition types.hpp:365
Point2i Point
Definition types.hpp:209
std::string String
Definition cvstd.hpp:151
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a simple, thick, or filled up-right rectangle.
Size getTextSize(const String &text, int fontFace, double fontScale, int thickness, int *baseLine)
Calculates the width and height of a text string.
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)
Draws a text string.
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a line segment connecting two points.
@ FONT_HERSHEY_SCRIPT_SIMPLEX
hand-writing style font
Definition imgproc.hpp:910
Parameters
textInput text string.
fontFaceFont to use, see HersheyFonts.
fontScaleFont scale factor that is multiplied by the font-specific base size.
thicknessThickness of lines used to render the text. See putText for details.
[out]baseLiney-coordinate of the baseline relative to the bottom-most text point.
Returns
The size of a box that contains the specified text.
See also
putText

◆ getTextSize() [2/2]

Rect cv::getTextSize ( Size imgsize,
const String & text,
Point org,
FontFace & fface,
int size,
int weight = 0,
PutTextFlags flags = PUT_TEXT_ALIGN_LEFT,
Range wrap = Range() )
Python:
cv.getTextSize(text, fontFace, fontScale, thickness) -> retval, baseLine
cv.getTextSize(imgsize, text, org, fface, size[, weight[, flags[, wrap]]]) -> retval

#include <opencv2/imgproc.hpp>

Calculates the bounding rect for the text.

The function cv::getTextSize calculates and returns the size of a box that contains the specified text. That is, the following code renders some text, the tight box surrounding it, and the baseline: :

Parameters
imgsizeSize of the target image, can be empty
textText string to be drawn.
orgBottom-left corner of the first character of the printed text (see PUT_TEXT_ALIGN_... though)
ffaceThe font to use for the text
sizeFont size in pixels (by default) or pts
weightFont weight, 100..1000, where 100 is "thin" font, 400 is "regular", 600 is "semibold", 800 is "bold" and beyond that is "black". The default weight means "400" for variable-weight fonts or whatever "default" weight the used font provides.
flagsVarious flags, see PUT_TEXT_...
wrapThe optional text wrapping range; see 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>

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.

Parameters
imgImage.
pt1First point of the line segment.
pt2Second point of the line segment.
colorLine color.
thicknessLine thickness.
lineTypeType of the line. See LineTypes.
shiftNumber of fractional bits in the point coordinates.

◆ 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>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ 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>

Draws several polygonal curves.

Parameters
imgImage.
ptsArray of polygonal curves.
isClosedFlag indicating whether the drawn polylines are closed or not. If they are closed, the function draws a line from the last vertex of each curve to its first vertex.
colorPolyline color.
thicknessThickness of the polyline edges.
lineTypeType of the line segments. See LineTypes
shiftNumber of fractional bits in the vertex coordinates.

The function cv::polylines draws one or more polygonal curves.

◆ putText() [1/2]

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
cv.putText(img, text, org, color, fface, size[, weight[, flags[, wrap]]]) -> retval, img

#include <opencv2/imgproc.hpp>

Draws a text string.

The function cv::putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by question marks. See getTextSize for a text rendering code example.

Parameters
imgImage.
textText string to be drawn.
orgBottom-left corner of the text string in the image.
fontFaceFont type, see HersheyFonts.
fontScaleFont scale factor that is multiplied by the font-specific base size.
colorText color.
thicknessThickness of the lines used to draw a text.
lineTypeLine type. See LineTypes
bottomLeftOriginWhen true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.

◆ putText() [2/2]

Point cv::putText ( InputOutputArray img,
const String & text,
Point org,
Scalar color,
FontFace & fface,
int size,
int weight = 0,
PutTextFlags flags = PUT_TEXT_ALIGN_LEFT,
Range wrap = Range() )
Python:
cv.putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]]) -> img
cv.putText(img, text, org, color, fface, size[, weight[, flags[, wrap]]]) -> retval, img

#include <opencv2/imgproc.hpp>

Draws a text string using specified font.

The function cv::putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by question marks. See getTextSize for a text rendering code example. The function returns the coordinates in pixels from where the text can be continued.

Parameters
imgImage.
textText string to be drawn.
orgBottom-left corner of the first character of the printed text (see PUT_TEXT_ALIGN_... though)
colorText color.
ffaceThe font to use for the text
sizeFont size in pixels (by default) or pts
weightFont weight, 100..1000, where 100 is "thin" font, 400 is "regular", 600 is "semibold", 800 is "bold" and beyond that is "black". The parameter is ignored if the font is not a variable font or if it does not provide variation along 'wght' axis. If the weight is 0, then the weight, currently set via setInstance(), is used.
flagsVarious flags, see PUT_TEXT_...
wrapThe optional text wrapping range: In the case of left-to-right (LTR) text if the printed character would cross wrap.end boundary, the "cursor" is set to wrap.start. In the case of right-to-left (RTL) text it's vice versa. If the parameters is not set, [org.x, img.cols] is used for LTR text and [0, org.x] is for RTL one.

◆ 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>

Draws a simple, thick, or filled up-right rectangle.

The function cv::rectangle draws a rectangle outline or a filled rectangle whose two opposite corners are pt1 and pt2.

Parameters
imgImage.
pt1Vertex of the rectangle.
pt2Vertex of the rectangle opposite to pt1 .
colorRectangle color or brightness (grayscale image).
thicknessThickness of lines that make up the rectangle. Negative values, like FILLED, mean that the function has to draw a filled rectangle.
lineTypeType of the line. See LineTypes
shiftNumber of fractional bits in the point coordinates.

◆ 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>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

use rec parameter as alternative specification of the drawn rectangle: r.tl() and r.br()-Point(1,1) are opposite corners