Nodes/opencv-comfyui/OpenCV convexHull_0
ComfyUI Node

OpenCV convexHull_0

Rubber-band outlines with convexHull — the shape-analysis workhorse

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV convexHull_0
  • points
  • hull
  • nparray
clockwise
returnPoints

The convex hull is the shape you'd get if you stretched a rubber band around a pile of points - the smallest convex polygon that contains all of them. convexHull_0 computes exactly that from an NPARRAY of points, and it's one of the more genuinely useful geometry nodes in the opencv-comfyui pack, because it turns noisy, irregular detected regions into clean, simple outlines.

The inputs are points (NPARRAY), plus two booleans: clockwise and returnPoints. The output is a single NPARRAY - either the hull's points, or indices into the original points array, depending on returnPoints. The one setting you actually care about is returnPoints:

  • True (default): you get the actual hull points - a (M, 1, 2) array you can draw, measure, or feed to other geometry nodes.
  • False: you get indices into the original point array instead. This matters for one specific downstream consumer - convexityDefects_0 requires an index-form hull - so flip it when you're feeding that node.

clockwise just controls the winding order of the output points (True = clockwise). It matters if the ordering has to match something downstream; otherwise leave it and don't sweat it.

Where it fits

This is the classic shape-analysis layer that sits under the detection loop ComfyUI is built around. The modidex detection docs describe getting masks from detectors; this is what you do after - when you've got a contour from findContours_0 and you want a tidy boundary instead of a jagged one, or you want to know whether a detected region is roughly convex or has big indentations. Combine it with contourArea_0 to measure the hull's area, and the ratio of hull area to contour area is a classic compactness/fill score - a cheap way to tell "blob" from "scalloped mess."

It's also a classic preprocessing step for hand/gesture work: hull of the hand outline, then convexityDefects_0 finds the finger valleys. That pipeline is a staple of OpenCV tutorials, and if that's your project, this is your node.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib

Or ComfyUI Manager → opencv-comfyui → restart. No models.

Troubleshooting

  • The input is points, not an image - wire in the contour output of findContours_0 (or any (N, 1, 2) point array), not a picture. Wrong shapes throw assertion errors.
  • Keep the nparray/IMAGE bridge straight: Image2Nparray (batch 1 only) in, Nparrays2Image out. Hull point arrays aren't images and won't display; if you want to see the hull, you'd draw it onto a copy first with a polylines/drawContours node from this same pack.
  • convexHull_0 and convexHull_1 are the identical MatLike/UMat overload pair - same node twice. Either works.
Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
pointsNPARRAY
clockwiseBOOLEAN
returnPointsBOOLEAN
hulloptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY