Skip to content

approxPolyN

geometryfunctionOpenCV 5.0.0
import { approxPolyN } from '@banou/opencv-wasm'

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

ARGUMENTScurve, approxCurve, nsides, epsilon_percentage
FUNCTIONapproxPolyN
RETURN TYPEvoid
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Approximates a polygon with a convex hull with a specified accuracy and number of sides.

T he cv::approxPolyN function approximates a polygon with *a convex hull so that the difference between the contour area of the original contour and the new polygon is minimal. It uses a greedy algorithm for contracting two vertices into one in such a way that the additional area is minimal. Straight lines formed by each edge of the convex contour are drawn and the areas of the resulting triangles are considered. Each vertex will lie either on the original contour or outside it.

The algorithm based on the paper [LowIlie2003] .

approxPolyN(curve: Mat, approxCurve: Mat, nsides: number, epsilon_percentage: number, ensure_convex: boolean): void;
3 available overloads
approxPolyN(curve: Mat, approxCurve: Mat, nsides: number): void;
approxPolyN(curve: Mat, approxCurve: Mat, nsides: number, epsilon_percentage: number): void;
approxPolyN(curve: Mat, approxCurve: Mat, nsides: number, epsilon_percentage: number, ensure_convex: boolean): void;
curve

Input vector of a 2D points stored in std::vector or Mat, points must be float or integer.

approxCurve

Output destination, filled by the native operation. Result of the approximation. The type is vector of a 2D point (Point2f or Point) in std::vector or Mat.

nsides

The parameter defines the number of sides of the result polygon.

epsilon_percentage

defines the percentage of the maximum of additional area. If it equals -1, it is not used. Otherwise algorithm stops if additional area is greater than contourArea(_curve) * percentage. If additional area exceeds the limit, algorithm returns as many vertices as there were at the moment the limit was exceeded.

ensure_convex

If it is true, algorithm creates a convex hull of input contour. Otherwise input vector should be convex.

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.