Nodes/comfyui_cv/CV Delaunay / Voronoi
ComfyUI Node

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).

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Delaunay / Voronoi
  • points
  • bounds
  • triangles
  • edges
  • facets
  • centers
  • count
margin10
Categoryimage/CV/points

Inputs (3)

NameTypeDefaultDescription
pointsNPARRAYNx2 (or Nx1x2) point set to triangulate. Duplicate points collapse to one vertex.
marginFLOAT100–10000Padding 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.
boundsoptNPARRAY,IMAGEOptional 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)

NameTypeDescription
trianglesCV_CONTOURSOne 3-point contour per Delaunay triangle. Triangles touching Subdiv2D's virtual outer vertices are dropped, so every one lies inside the rectangle.
edgesNPARRAYMx4 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).
facetsCV_CONTOURSOne contour per VORONOI cell, in the same order as 'centers' - the region of the plane closest to that point. Draw with 'CV Draw Contours'.
centersNPARRAYKx2 float32 the facets belong to: the input points after de-duplication and clamping into the rectangle.
countINTNumber of triangles; 0 for fewer than 3 distinct points - a valid result, not an error.