OpenCV connectedComponentsWithStats_1
The stats workhorse, duplicated (connectedComponentsWithStats_1)
- image
- labels
- stats
- centroids
- int
- nparray_1
- nparray_2
- nparray_3
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 theCV_8UC1assertion. - connectivity (INT) -
4or8. Use8. - ltype (INT) -
4(CV_32S) or2(CV_16U). Use4. - labels / stats / centroids (NPARRAY, optional) - out-parameters; skip them per the README.
- Outputs:
int(count),nparray_1(labels),nparray_2(stats -N×5of left/top/width/height/area),nparray_3(centroids -N×2of 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.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | NPARRAY | — | |
| connectivity | INT | — | |
| ltype | INT | — | |
| labelsopt | NPARRAY | — | |
| statsopt | NPARRAY | — | |
| centroidsopt | NPARRAY | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| int | INT | — |
| nparray_1 | NPARRAY | — |
| nparray_2 | NPARRAY | — |
| nparray_3 | NPARRAY | — |