OpenCV moments_1
The duplicate you can ignore, and the same stringified stats
- array
- literal
moments_1 is the identical twin of moments_0. Same inputs - array (NPARRAY) plus a binaryImage toggle - same single literal output, same underlying cv2.moments call. If you've read the other article, you know everything this node does. The reason both exist is the pack's generator emitting one node per OpenCV overload (MatLike vs UMat) and then collapsing both array types onto the same NPARRAY slot. The numbering is parser residue, not a behavioral difference.
What it's for
cv2.moments computes the spatial, central, and normalized moments of a binary shape: m00 is the area, m10/m00 and m01/m00 give the centroid, and the Hu moments are rotation/scale-invariant shape signatures. In a ComfyUI workflow you reach for it when you've produced a mask and want hard numbers about the blob - how big, where its center is, how it's oriented.
The one thing to remember: the output is a single STRING containing the stringified Moments object (m00=..., mu20=..., ...). It's a read-it-off-the-widget tool, not a source of floats you can wire into math. If you need actual numbers downstream, you'll be parsing text.
Inputs that matter
array- single-channelNPARRAY. Grayscale or a binary mask only; 3-channel input throws theimg.type() == CV_8UC1assertion error.binaryImage- setTrueto treat all non-zero pixels as 1. That's what you want for a mask: exact pixel counts rather than intensity-weighted values.
Installing
Via ComfyUI Manager (search "opencv-comfyui") or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart, done. opencv-contrib-python is the only real dependency and it's almost certainly already in your environment.
Pipeline
IMAGE → Image2Nparray → moments_1. Image2Nparray does the RGB→BGR flip and only accepts batch_size==1 (use ImageFromBatch for bigger batches). The output is text, not an image, so it ends the chain - don't route it into Nparrays2Image or you'll hit the classic 'NoneType' object has no attribute 'shape' error.
Troubleshooting
CV_8UC1assertion - your input is 3-channel; make it grayscale first.- Long string output - that's the
Momentsobject repr, expected. - Which variant?
_0or_1, identical. Pick_0for consistency with online docs.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| array | NPARRAY | — | |
| binaryImage | BOOLEAN | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| literal | STRING | — |