Nodes/opencv-comfyui/OpenCV connectedComponents_1
ComfyUI Node

OpenCV connectedComponents_1

ConnectedComponents_0's twin — same blob counter, spare slot

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV connectedComponents_1
  • image
  • labels
  • int
  • nparray
connectivity
ltype

connectedComponents_1 is connectedComponents_0, duplicated. I diffed the two node classes in the pack source - identical implementation, same cv2.connectedComponents call, same outputs. The pack auto-generates a node per overload in OpenCV's type stubs, this function declared two signatures, and you get two identical nodes. Pick _0, ignore this one, and you'll miss nothing.

The short version

Labels every connected region in a binary mask and counts them:

  • image (NPARRAY) - 8-bit single-channel binary mask (CV_8UC1). Convert via Image2Nparray, then cvtColor with code=6 (BGR2GRAY), or hit the (-215:Assertion failed) img.type() == CV_8UC1 error.
  • connectivity (INT) - 4 (edge neighbors) or 8 (corners count). 8 for most uses.
  • ltype (INT) - 4 (CV_32S) or 2 (CV_16U, caps at 65535 labels). Use 4.
  • labels (NPARRAY, optional) - out-parameter; skip it.
  • Outputs: int (component count, background included) and nparray (label map).

Classic use: count how many blobs are in a mask, or decide whether a mask is one object or many. If you need per-blob sizes to filter speckles, use connectedComponentsWithStats_0 instead. And don't preview the label map as an image - label IDs aren't pixel intensities, so it renders as noise.

Install

Standard for the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

or ComfyUI Manager → "opencv-comfyui". Needs opencv-python-contrib. Environment gotchas are the pack-wide ones: conflicting OpenCV installs (Cannot import name 'guidedFilter' from 'cv2.ximgproc') and Image2Nparray's batch-size-1 limit. Same node, same rules - the _1 here buys you nothing but a second entry in the node search.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
imageNPARRAY
connectivityINT
ltypeINT
labelsoptNPARRAY

Outputs (2)

NameTypeDescription
intINT
nparrayNPARRAY