Contour tracing
Trace the boundary of each binary region as an ordered sequence of points.
The inward notch distinguishes the original boundary from its convex hull.
Locate an unvisited boundary pixel.
Follow the region boundary in order.
Record points and, when requested, parent-child contour relationships.
Record points and, when requested, parent-child contour relationships.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Draw outlines of white regions after thresholding.
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
Measure outlines, distinguish holes, simplify shapes or draw boundaries.
How it works
- 01Locate an unvisited boundary pixel.
- 02Follow the region boundary in order.
- 03Record points and, when requested, parent-child contour relationships.
binary mask → ordered boundaries + hierarchy
What to tune
RETR_EXTERNAL keeps outer boundaries; RETR_TREE retains nesting. CHAIN_APPROX_SIMPLE removes redundant points on straight runs.
Where it breaks down
Contour area and foreground pixel count are different measurements. Retrieval and approximation choices change the output topology and point count.
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.
Related methods
Global thresholding
Divide pixels using one intensity threshold, or choose it automatically with Otsu or the triangle method.
Adaptive thresholding
Compute a different intensity threshold for each local neighbourhood.
Connected components
Give every connected foreground region a distinct integer label.
Marker-based watershed
Grow labelled regions across an image until competing regions meet at boundaries.