OpenCV sumElems_0
Adds up every pixel, returns a string — a stats oddity
- src
- literal
sumElems_0 adds up every pixel value in the image, per channel, and hands you the total as a string. That's it. One input, src (NPARRAY), no optional knobs, and a single output called literal - because what comes out is the string representation of an OpenCV Scalar, something like (10487656.0, 9982341.0, 9123456.0, 0.0), one sum per channel.
Is that useful? Sometimes, and honestly. The obvious trick: that sum divided by the pixel count is the mean brightness per channel, so with a division node downstream you've got a cheap "is this frame overexposed?" check. Sum over time is a naive motion/energy metric. And in a debugging workflow, it's a quick sanity probe - is there anything in this array at all, or did an upstream node hand you zeros? That kind of "is my pipeline alive" check is worth more than it looks.
But it's also the clearest example of the pack's auto-generated weirdness. The README literally has a troubleshooting entry for the exact failure this node causes: you take its output, feed it into Nparrays2Image, and get 'NoneType' object has no attribute 'shape' - because the output is a scalar, not an image. This is a node whose output is a string and whose type is STRING, and if you treat it like a picture you're going to be confused for a minute. The README's advice applies verbatim: "Not every return type of nparray is actually an image." Here it's not even an nparray.
The useful mental model. This pack wraps raw OpenCV functions with zero hand-tuning, and sumElems is a raw stats function that happens to be top-level. In a normal pipeline you'd reach for cv2.mean or cv2.meanStdDev instead, and this pack has those too (mean_0, meanStdDev_0). If your actual goal is a single brightness number, mean_0 is the less weird route. If you want to live on the edge with a four-channel sum-as-string, you've found your node.
Install. ComfyUI Manager → search "opencv-comfyui", or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart. Needs opencv-contrib-python, numpy, torch; the Cannot import name 'guidedFilter' from 'cv2.ximgproc' startup error means conflicting OpenCV packages and has to be fixed first. And sumElems_1 is the identical twin - same single input, same string output, no difference worth caring about.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| src | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| literal | STRING | — |