Polygon approximation
Replace a dense curve with fewer vertices while limiting geometric deviation.
The inward notch distinguishes the original boundary from its convex hull.
Connect the end points of a curve segment.
Find the point farthest from that segment.
Split if its deviation exceeds epsilon, then repeat.
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
Experiment at pixel level
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.
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
Select a pixel
Select a pixel
When to use it
Simplify contours, identify approximate quadrilaterals, or reduce geometry for rendering.
How it works
- 01Connect the end points of a curve segment.
- 02Find the point farthest from that segment.
- 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.