Nodes/opencv-comfyui/OpenCV connectedComponentsWithStats_1
ComfyUI Node

OpenCV connectedComponentsWithStats_1

The stats workhorse, duplicated (connectedComponentsWithStats_1)

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV connectedComponentsWithStats_1
  • image
  • labels
  • stats
  • centroids
  • int
  • nparray_1
  • nparray_2
  • nparray_3
connectivity
ltype

connectedComponentsWithStats_1 is connectedComponentsWithStats_0 with a different ID - same cv2.connectedComponentsWithStats call, same four outputs, identical implementation. The pack emits a node per overload in OpenCV's type stubs and this function declared two signatures, so you get two identical nodes. Use the _0 one; this page exists so the numbering makes sense.

The short version

Labels every connected region in a binary mask and reports per-blob statistics:

  • image (NPARRAY) - 8-bit single-channel binary mask. Convert via Image2Nparray + cvtColor (code=6), or get the CV_8UC1 assertion.
  • connectivity (INT) - 4 or 8. Use 8.
  • ltype (INT) - 4 (CV_32S) or 2 (CV_16U). Use 4.
  • labels / stats / centroids (NPARRAY, optional) - out-parameters; skip them per the README.
  • Outputs: int (count), nparray_1 (labels), nparray_2 (stats - N×5 of left/top/width/height/area), nparray_3 (centroids - N×2 of x/y).

The classic use: filter mask speckles by area - keep the stats rows for components above your pixel threshold, discard the rest. This is the practical workhorse of the connected-components family, since the pack doesn't ship findContours/drawContours.

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. Pack-wide gotchas apply: conflicting OpenCV installs (Cannot import name 'guidedFilter' from 'cv2.ximgproc') and Image2Nparray's batch-size-1 limit. Same node, same outputs, same everything - the only thing _1 adds is a second entry in your node search.

Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
imageNPARRAY
connectivityINT
ltypeINT
labelsoptNPARRAY
statsoptNPARRAY
centroidsoptNPARRAY

Outputs (4)

NameTypeDescription
intINT
nparray_1NPARRAY
nparray_2NPARRAY
nparray_3NPARRAY