Skip to content

Polygon approximation

Replace a dense curve with fewer vertices while limiting geometric deviation.

Try it on your image ↓

VISUAL WALKTHROUGHShape
REFERENCE INPUTShape with a concavity

The inward notch distinguishes the original boundary from its convex hull.

RESULTReduced vertex sequence

Split if its deviation exceeds epsilon, then repeat.

STEP 03 / 03

Split if its deviation exceeds epsilon, then repeat.

Illustrative example. The stages explain the method; they are not a live OpenCV execution.

Try it on an image

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

Approximate thresholded contours with polygons. Epsilon is a fraction of each contour perimeter.

The engine loads on your first run. Your images stay in this browser.

Input448 × 320
OutputWaiting for a result

Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.

Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Simplify contours, identify approximate quadrilaterals, or reduce geometry for rendering.

How it works

  1. 01Connect the end points of a curve segment.
  2. 02Find the point farthest from that segment.
  3. 03Split if its deviation exceeds epsilon, then repeat.

maximum retained deviation controlled by ε

What to tune

epsilon uses the same coordinate units as the contour; closed specifies whether the curve is a loop.

Where it breaks down

A high epsilon erases real corners. It is a geometric tolerance, not a guarantee of the intended semantic shape.

TypeScript API

Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.

All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.