Convex hulls and defects
Wrap a point set in its smallest convex boundary and measure inward deviations.
The inward notch distinguishes the original boundary from its convex hull.
Order the points along the outside of the set.
Discard turns that bend inward.
For convexity defects, compare the original contour with hull edges.
For convexity defects, compare the original contour with hull edges.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Draw convex hulls around thresholded connected contours.
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
Estimate envelopes, detect concavities, or build coarse collision shapes.
How it works
- 01Order the points along the outside of the set.
- 02Discard turns that bend inward.
- 03For convexity defects, compare the original contour with hull edges.
hull = smallest convex set containing all points
What to tune
returnPoints chooses coordinates or contour indices. convexityDefects needs hull indices.
Where it breaks down
The hull intentionally discards concave detail. Defect depth uses the native fixed-point representation described in the API.
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.