MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ find_contours() [2/2]

MAYAFLUX_API std::vector< Contour > MayaFlux::Kinesis::Vision::find_contours ( std::span< const float >  mask,
uint32_t  w,
uint32_t  h,
float  min_area = 0.0F,
uint32_t  max_contours = 0,
uint32_t  max_points_per_contour = 0 
)

Extract outer and hole contours from a binary mask.

Labels 8-connected foreground components and traces their outer boundaries with Moore neighborhood following. Enclosed 4-connected background regions are traced as holes, with parent_label naming their enclosing foreground component. Background connected to an image edge is excluded. Outer contours use Contour::no_parent (0xFFFFFFFF) as their parent_label. Each contour closes from its last point to its first. Closure follows the starting directed edge so touching branches may revisit the start pixel.

Area is (absolute pixel polygon area + half the pixel perimeter + 1) divided by w * h. Perimeter is the closed polygon length in pixels.

Contours with fewer than 3 points are discarded. Contours whose normalised area is below min_area are discarded after tracing. A nonzero max_contours sorts by descending area and retains at most that many contours. Outer boundaries and holes share this limit. A nonzero max_points_per_contour stops each trace at that many points; measurements use the retained polygon, including its closing edge.

Parameters
maskSingle-channel float span, size must be w * h.
wImage width in pixels.
hImage height in pixels.
min_areaMinimum normalised area [0,1] to retain. Default 0 (no filter).
max_contoursMaximum number of contours to return. 0 means no limit.
max_points_per_contourMaximum trace length. 0 means no caller limit.
Returns
Contours with normalised points and area, and pixel perimeter.

Definition at line 111 of file Contours.cpp.

114{
115 if (w == 0 || h == 0)
116 return {};
117
118 const auto cc = connected_components(mask, w, h);
119 return find_contours(cc, w, h, min_area, max_contours, max_points_per_contour);
120}
uint32_t h
Definition InkPress.cpp:29

References connected_components(), find_contours(), and h.

Referenced by find_contours(), and MayaFlux::Kinesis::Vision::VisionExecutor::run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: