Color Convention
For color images, the channel ordering is normally Blue, Green, Red (BGR). This is what imshow, imread, and imwrite expect. If you form a color using the Scalar constructor, it should look like:Line Drawing
line
Draws a line segment connecting two points.InputOutputArray
Image.
Point
First point of the line segment.
Point
Second point of the line segment.
Scalar
Line color.
int
default:"1"
Line thickness.
int
default:"LINE_8"
Type of the line. See LineTypes.
int
default:"0"
Number of fractional bits in the point coordinates.
- C++
- Python
arrowedLine
Draws an arrow segment pointing from the first point to the second one.InputOutputArray
Image.
Point
The point the arrow starts from.
Point
The point the arrow points to.
Scalar
Line color.
int
default:"1"
Line thickness.
int
default:"8"
Type of the line. See LineTypes.
int
default:"0"
Number of fractional bits in the point coordinates.
double
default:"0.1"
The length of the arrow tip in relation to the arrow length.
Shape Drawing
rectangle
Draws a simple, thick, or filled up-right rectangle.InputOutputArray
Image.
Point
Vertex of the rectangle.
Point
Vertex of the rectangle opposite to pt1.
Rect
Alternative rectangle specification.
Scalar
Rectangle color or brightness (grayscale image).
int
default:"1"
Thickness of lines that make up the rectangle. Negative values, like FILLED, mean that the function has to draw a filled rectangle.
int
default:"LINE_8"
Type of the line. See LineTypes.
int
default:"0"
Number of fractional bits in the point coordinates.
- C++
- Python
circle
Draws a circle.InputOutputArray
Image where the circle is drawn.
Point
Center of the circle.
int
Radius of the circle.
Scalar
Circle color.
int
default:"1"
Thickness of the circle outline, if positive. Negative values, like FILLED, mean that a filled circle is to be drawn.
int
default:"LINE_8"
Type of the circle boundary. See LineTypes.
int
default:"0"
Number of fractional bits in the coordinates of the center and in the radius value.
- C++
- Python
ellipse
Draws a simple or thick elliptic arc or fills an ellipse sector.InputOutputArray
Image.
Point
Center of the ellipse.
Size
Half of the size of the ellipse main axes.
double
Ellipse rotation angle in degrees.
double
Starting angle of the elliptic arc in degrees.
double
Ending angle of the elliptic arc in degrees.
RotatedRect
Alternative ellipse representation via RotatedRect. This means that the function draws an ellipse inscribed in the rotated rectangle.
Scalar
Ellipse color.
int
default:"1"
Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.
int
default:"LINE_8"
Type of the ellipse boundary. See LineTypes.
int
default:"0"
Number of fractional bits in the coordinates of the center and values of axes.
Polygon Drawing
polylines
Draws several polygonal curves.InputOutputArray
Image.
InputArrayOfArrays
Array of polygonal curves.
bool
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.
Scalar
Polyline color.
int
default:"1"
Thickness of the polyline edges.
int
default:"LINE_8"
Type of the line segments. See LineTypes.
int
default:"0"
Number of fractional bits in the vertex coordinates.
fillPoly
Fills the area bounded by one or more polygons.InputOutputArray
Image.
InputArrayOfArrays
Array of polygons where each polygon is represented as an array of points.
Scalar
Polygon color.
int
default:"LINE_8"
Type of the polygon boundaries. See LineTypes.
int
default:"0"
Number of fractional bits in the vertex coordinates.
Point
default:"Point()"
Optional offset of all points of the contours.
fillConvexPoly
Fills a convex polygon.InputOutputArray
Image.
InputArray
Polygon vertices.
Scalar
Polygon color.
int
default:"LINE_8"
Type of the polygon boundaries. See LineTypes.
int
default:"0"
Number of fractional bits in the vertex coordinates.
Text Rendering
putText
Draws a text string.InputOutputArray
Image.
String
Text string to be drawn.
Point
Bottom-left corner of the text string in the image.
int
Font type. See HersheyFonts.
double
Font scale factor that is multiplied by the font-specific base size.
Scalar
Text color.
int
default:"1"
Thickness of the lines used to draw a text.
int
default:"LINE_8"
Line type. See LineTypes.
bool
default:"false"
When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.
- C++
- Python
getTextSize
Calculates the width and height of a text string.String
Input text string.
int
Font to use. See HersheyFonts.
double
Font scale factor that is multiplied by the font-specific base size.
int
Thickness of lines used to render the text.
int*
y-coordinate of the baseline relative to the bottom-most text point.
Enumerations
LineTypes
Types of line:FILLED(-1) - Filled shapeLINE_4(4) - 4-connected lineLINE_8(8) - 8-connected lineLINE_AA(16) - Antialiased line
HersheyFonts
Hershey font types:FONT_HERSHEY_SIMPLEX(0) - Normal size sans-serif fontFONT_HERSHEY_PLAIN(1) - Small size sans-serif fontFONT_HERSHEY_DUPLEX(2) - Normal size sans-serif font (more complex than SIMPLEX)FONT_HERSHEY_COMPLEX(3) - Normal size serif fontFONT_HERSHEY_TRIPLEX(4) - Normal size serif font (more complex than COMPLEX)FONT_HERSHEY_COMPLEX_SMALL(5) - Smaller version of COMPLEXFONT_HERSHEY_SCRIPT_SIMPLEX(6) - Hand-writing style fontFONT_HERSHEY_SCRIPT_COMPLEX(7) - More complex variant of SCRIPT_SIMPLEXFONT_ITALIC(16) - Flag for italic font
MarkerTypes
Marker types used for the drawMarker function:MARKER_CROSS(0) - A crosshair marker shapeMARKER_TILTED_CROSS(1) - A 45 degree tilted crosshair marker shapeMARKER_STAR(2) - A star marker shapeMARKER_DIAMOND(3) - A diamond marker shapeMARKER_SQUARE(4) - A square marker shapeMARKER_TRIANGLE_UP(5) - An upwards pointing triangle marker shapeMARKER_TRIANGLE_DOWN(6) - A downwards pointing triangle marker shape
