Nodes/ComfyUI CV/cv2.convexHull
ComfyUI Node

cv2.convexHull

The rubber band around a point set

By bmad4ever·Created 3 months ago·Updated 14 days ago· 1
cv2.convexHull
  • points
  • nparray
◄clockwisefalse►
◄returnPointstrue►

What it does

Stretch a rubber band around a set of points and let go. The shape it settles into is the convex hull: the smallest convex polygon containing every point. No interior points, no dents, no concavities - just the outline.

That makes it the standard first tool for taming a noisy contour. findContours on a real mask gives you a jagged polygon with hundreds of vertices and a stuttery boundary; its hull is a clean 8-vertex shape you can actually reason about, measure, and compare against other shapes. It's also half of the classic OpenCV hand-gesture recipe (hull + defects = where the fingers are), for reasons the convexityDefects article covers.

It's a raw wrapper from ComfyUI CV (bmad4ever/comfyui_cv), category image/CV/low-level/cv2 C.

How it works

Give it a point array, get back the hull. The implementation is a monotone-chain / Sklansky-style scan: sort, sweep, discard interior points. Cost is dominated by the point count, so it's cheap on contour-sized inputs and still fine on thousands of points.

The two flags change what you get back, and one of them exists for a downstream consumer:

  • returnPoints=True (the default) - you get the hull as points, an (H,1,2) array. That's what you want for drawing, for area, for enclosing shapes.
  • returnPoints=False - you get the hull as indices into your original array. This form is useless on its own and mandatory for one thing: cv2.convexityDefects requires index form. The pack's own tooltip for the defect node says it needs "hull INDICES from cv2.convexHull with returnPoints=False", and that's the only reason this flag exists in a normal workflow.

clockwise sets the orientation of the returned points. It matters more than it sounds, because orientation is what makes contourArea's sign meaningful - if you're computing a hull area for a solidity ratio (contour area ÷ hull area), flip the flag and be consistent about it.

Inputs and outputs that matter

  • points - required, NPARRAY only. The author's tooltip is explicit that this is a point set: an IMAGE or MASK link is not accepted. Layout is the classic (N,1,2) or (N,2), typically from CV Contour To Points.
  • clockwise - optional BOOLEAN, default False, advanced input.
  • returnPoints - optional BOOLEAN, default True, advanced input. Set it False only when feeding the defect node.
  • nparray - the hull, as points or indices depending on the flag above.

Uses in this pack: hull points feed the drawing nodes (CV Draw Polygon, cv2.polylines), and CV Region Properties reports convexity-derived columns (convexity defects, rectangularity) without you assembling the raw nodes - worth a look before you build the pipeline by hand. If you specifically want "the smallest shape of a given kind containing this contour", CV Enclosing Circle is the curated sibling.

Installing the pack

Manager → search ComfyUI CV, or:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv

Restart ComfyUI. Python ≥ 3.12 and a V3 node API build are required; the dependency is opencv-contrib-python-headless~=5.0.0.93.

Where people get burned

  • Mixing up the two output forms. Hull points where indices were wanted gives you either an exception or a plausible-looking wrong shape, depending on what's downstream. If convexityDefects is complaining, returnPoints is almost always the reason.
  • Assuming the hull keeps your points. It discards interior ones. If you wanted a simplified-but-faithful outline, that's approxPolyDP (approxPolyN in the registry), not this.
  • Comparing a hull against a hull computed a different way. clockwise changes point order, which changes the sign of an oriented area computation. Pick an orientation and keep it for the whole comparison.
  • Non-finite or duplicate points. NaNs propagate into geometric routines in ways that range from an exception to a garbage hull. If your points came from a divide or a dehomogenise step, check for them.
  • The pack's own framing, once, so it's not a shock later. The README states the code is heavily LLM-assisted, names a real overfitting incident (Hu moments), says updates are not planned, and advises against production use without reviewing the source yourself. It also warns that the registry is generated from your installed OpenCV build, so a listed node can still fail at runtime. There's no community corpus behind this pack at all - searching Reddit returns nothing - so verification is on you. And the shared trap that takes out every OpenCV-based pack at once (a non-contrib wheel replacing the contrib one, or DLL load failed while importing cv2 on Windows portable) has a helper in the repo: tools/repair_opencv_contrib.py --check.
Categoryimage/CV/low-level/cv2 C

Inputs (3)

NameTypeDefaultDescription
pointsNPARRAY - - - A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here.
clockwiseoptBOOLEANfalse - - - Preset to the OpenCV default (False).
returnPointsoptBOOLEANtrue - - - Preset to the OpenCV default (True).

Outputs (1)

NameTypeDescription
nparrayNPARRAY—