OpenCV connectedComponents_1
ConnectedComponents_0's twin — same blob counter, spare slot
- image
- labels
- int
- nparray
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 viaImage2Nparray, thencvtColorwithcode=6(BGR2GRAY), or hit the(-215:Assertion failed) img.type() == CV_8UC1error. - connectivity (INT) -
4(edge neighbors) or8(corners count).8for most uses. - ltype (INT) -
4(CV_32S) or2(CV_16U, caps at 65535 labels). Use4. - labels (NPARRAY, optional) - out-parameter; skip it.
- Outputs:
int(component count, background included) andnparray(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.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | NPARRAY | — | |
| connectivity | INT | — | |
| ltype | INT | — | |
| labelsopt | NPARRAY | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| int | INT | — |
| nparray | NPARRAY | — |