Only a subset of Hershey fonts are supported
Only a subset of Hershey fonts are supported
The function [cv::arrowedLine] draws an arrow between pt1 and pt2 points in the image. See also [line].
Image.
The point the arrow starts from.
The point the arrow points to.
Line color.
Line thickness.
Type of the line. See LineTypes
Number of fractional bits in the point coordinates.
The length of the arrow tip in relation to the arrow length
The function [cv::circle] draws a simple or filled circle with a given center and radius.
Image where the circle is drawn.
Center of the circle.
Radius of the circle.
Circle color.
Thickness of the circle outline, if positive. Negative values, like FILLED, mean that a filled circle is to be drawn.
Type of the circle boundary. See LineTypes
Number of fractional bits in the coordinates of the center and in the radius value.
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 .
Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) .
First line point.
Second line point.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Image size. The image rectangle is Rect(0, 0, imgSize.width, imgSize.height) .
First line point.
Second line point.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Image rectangle.
First line point.
Second line point.
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: :
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
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], 0)).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);
}
When thickness=[FILLED], the function is designed to handle connected components with holes correctly even when no hierarchy date 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.
Destination image.
All the input contours. Each contour is stored as a point vector.
Parameter indicating a contour to draw. If it is negative, all the contours are drawn.
Color of the contours.
Thickness of lines the contours are drawn with. If it is negative (for example, thickness=FILLED ), the contour interiors are drawn.
Line connectivity. See LineTypes
Optional information about hierarchy. It is only needed if you want to draw only some of the contours (see maxLevel ).
Maximal 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.
Optional contour shift parameter. Shift all the drawn contours by the specified $\texttt{offset}=(dx,dy)$ .
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.
Image.
The point where the crosshair is positioned.
Line color.
The specific type of marker you want to use, see MarkerTypes
The length of the marker axis [default = 20 pixels]
Line thickness.
Type of the line, See LineTypes
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.
Image.
Center of the ellipse.
Half of the size of the ellipse main axes.
Ellipse rotation angle in degrees.
Starting angle of the elliptic arc in degrees.
Ending angle of the elliptic arc in degrees.
Ellipse color.
Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.
Type of the ellipse boundary. See LineTypes
Number of fractional bits in the coordinates of the center and values of axes.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Image.
Alternative ellipse representation via RotatedRect. This means that the function draws an ellipse inscribed in the rotated rectangle.
Ellipse color.
Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.
Type of the ellipse boundary. See LineTypes
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.
Center of the arc.
Half of the size of the ellipse main axes. See ellipse for details.
Rotation angle of the ellipse in degrees. See ellipse for details.
Starting angle of the elliptic arc in degrees.
Ending angle of the elliptic arc in degrees.
Angle between the subsequent polyline vertices. It defines the approximation accuracy.
Output vector of polyline vertices.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Center of the arc.
Half of the size of the ellipse main axes. See ellipse for details.
Rotation angle of the ellipse in degrees. See ellipse for details.
Starting angle of the elliptic arc in degrees.
Ending angle of the elliptic arc in degrees.
Angle between the subsequent polyline vertices. It defines the approximation accuracy.
Output vector of polyline vertices.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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).
Image.
Polygon vertices.
Polygon color.
Type of the polygon boundaries. See LineTypes
Number of fractional bits in the vertex coordinates.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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.
Image.
Array of polygons where each polygon is represented as an array of points.
Polygon color.
Type of the polygon boundaries. See LineTypes
Number of fractional bits in the vertex coordinates.
Optional offset of all points of the contours.
The fontSize to use for [cv::putText]
[cv::putText]
Font to use, see cv::HersheyFonts.
Pixel height to compute the fontScale for
Thickness of lines used to render the text.See putText for details.
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";
int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
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);
The size of a box that contains the specified text.
[putText]
Input text string.
Font to use, see HersheyFonts.
Font scale factor that is multiplied by the font-specific base size.
Thickness of lines used to render the text. See putText for details.
y-coordinate of the baseline relative to the bottom-most text point.
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.
Image.
First point of the line segment.
Second point of the line segment.
Line color.
Line thickness.
Type of the line. See LineTypes.
Number of fractional bits in the point coordinates.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The function [cv::polylines] draws one or more polygonal curves.
Image.
Array of polygonal curves.
Flag 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.
Polyline color.
Thickness of the polyline edges.
Type of the line segments. See LineTypes
Number of fractional bits in the vertex coordinates.
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.
Image.
Text string to be drawn.
Bottom-left corner of the text string in the image.
Font type, see HersheyFonts.
Font scale factor that is multiplied by the font-specific base size.
Text color.
Thickness of the lines used to draw a text.
Line type. See LineTypes
When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.
The function [cv::rectangle] draws a rectangle outline or a filled rectangle whose two opposite corners are pt1 and pt2.
Image.
Vertex of the rectangle.
Vertex of the rectangle opposite to pt1 .
Rectangle color or brightness (grayscale image).
Thickness of lines that make up the rectangle. Negative values, like FILLED, mean that the function has to draw a filled rectangle.
Type of the line. See LineTypes
Number of fractional bits in the point coordinates.
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
Generated using TypeDoc
Only a subset of Hershey fonts are supported