Skip to content

drawContours

Image processingfunctionOpenCV 5.0.0
import { drawContours } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

example: samples/python/snippets/contours.py An example program illustrates the use of findContours and drawContours in python example: samples/cpp/snippets/segment_objects.cpp An example using drawContours to clean up a background segmentation result 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: :

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.

drawContours(image: Mat, contours: MatVector, contourIdx: number, color: Scalar, thickness: number, lineType: number, hierarchy: Mat, maxLevel: number, offset: Point): void;
6 available overloads
drawContours(image: Mat, contours: MatVector, contourIdx: number, color: Scalar): void;
drawContours(image: Mat, contours: MatVector, contourIdx: number, color: Scalar, thickness: number): void;
drawContours(image: Mat, contours: MatVector, contourIdx: number, color: Scalar, thickness: number, lineType: number): void;
drawContours(image: Mat, contours: MatVector, contourIdx: number, color: Scalar, thickness: number, lineType: number, hierarchy: Mat): void;
drawContours(image: Mat, contours: MatVector, contourIdx: number, color: Scalar, thickness: number, lineType: number, hierarchy: Mat, maxLevel: number): void;
drawContours(image: Mat, contours: MatVector, contourIdx: number, color: Scalar, thickness: number, lineType: number, hierarchy: Mat, maxLevel: number, offset: Point): void;
image

Input/output value, modified by the native operation. Destination image.

contours

All the input contours. Each contour is stored as a point vector.

contourIdx

Parameter indicating a contour to draw. If it is negative, all the contours are drawn.

color

Color of the contours.

thickness

Thickness of lines the contours are drawn with. If it is negative (for example, thickness=#FILLED ), the contour interiors are drawn.

lineType

Line connectivity. See #LineTypes

hierarchy

Optional information about hierarchy. It is only needed if you want to draw only some of the contours (see maxLevel ).

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.

offset

Optional contour shift parameter. Shift all the drawn contours by the specified \texttt{offset}=(dx,dy) .

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.