CV Delaunay / Voronoi
Connects a point set into a triangle mesh (Delaunay triangulation) and its dual Voronoi diagram, via cv2.Subdiv2D - a stateful class the raw wrappers cannot expose. Delaunay is THE way to turn scattered points into a mesh: it maximises the smallest angle, so the triangles are as well-shaped as the points allow. Uses: face/image morphing and piecewise-affine warping (triangulate landmarks, warp each triangle), surface reconstruction from a sparse point cloud, and nearest-neighbour region maps (the Voronoi cell of a point is everything closer to it than to any other). Feed any Nx2 point set - detected corners, blob centres, k-means centroids, annotated points. Draw 'triangles'/'facets' with 'CV Draw Contours' or 'edges' with 'CV Draw Segments'. Fewer than 3 points is a valid result (empty outputs, count = 0).
- points
- bounds
- triangles
- edges
- facets
- centers
- count
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| points | NPARRAY | Nx2 (or Nx1x2) point set to triangulate. Duplicate points collapse to one vertex. | |
| margin | FLOAT | 100–10000 | Padding around the points' bounding box when no 'bounds' image is connected. Subdiv2D needs an enclosing rectangle and rejects points on its edge, so leave at least a pixel or two. |
| boundsopt | NPARRAY,IMAGE | Optional image whose SIZE defines the enclosing rectangle - connect the image the points came from so the Voronoi cells are clipped to it. Without it the rectangle is the points' bounding box plus 'margin'. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| triangles | CV_CONTOURS | One 3-point contour per Delaunay triangle. Triangles touching Subdiv2D's virtual outer vertices are dropped, so every one lies inside the rectangle. |
| edges | NPARRAY | Mx4 float32 (x1, y1, x2, y2) mesh edges - feed 'OpenCV Draw Segments' for a clean wireframe (each edge drawn once instead of three times per triangle). |
| facets | CV_CONTOURS | One contour per VORONOI cell, in the same order as 'centers' - the region of the plane closest to that point. Draw with 'CV Draw Contours'. |
| centers | NPARRAY | Kx2 float32 the facets belong to: the input points after de-duplication and clamping into the rectangle. |
| count | INT | Number of triangles; 0 for fewer than 3 distinct points - a valid result, not an error. |