Nodes/opencv-comfyui/OpenCV accumulate_0
ComfyUI Node

OpenCV accumulate_0

OpenCV accumulate_0

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV accumulate_0
  • src
  • dst
  • mask
  • nparray

accumulate_0 is a running total. It wraps cv2.accumulate(src, dst[, mask]), which does one thing: dst = dst + src. Feed it a frame, it adds that frame into a running accumulator; feed it the next frame, it adds that too. Loop it over a video and you end up with the summed image of every frame - which is the raw material for an average frame (divide by the count), for ghosting effects, for star trails, or for measuring total energy in a region over time.

It's a deliberately dumb math node, and that's the point. Where add_0 saturates and clips at 255 and refuses to go above uint8 range, accumulate is not saturating: it keeps adding into a floating-point accumulator until you stop it. That's the difference that makes the family useful for statistics rather than for eyeballing a blend.

How it works

The signature is cv2.accumulate(src, dst[, mask]). src is the image to fold in, dst is the accumulator, and both must be the same size. The catch - and this is the "expect dragons" moment - is that OpenCV requires dst to be a floating-point array (float32 or float64). Feed it a plain uint8 image from Image2Nparray and it dies with dst.type() == CV_32F assertion. That's the single most common way people bounce off this node.

The mask is optional and per-pixel: where the mask is nonzero it adds, where it's zero it leaves the accumulator untouched. Handy for accumulating only the region you care about.

The inputs that matter

  • src (NPARRAY) - the frame to add.
  • dst (NPARRAY, required) - the accumulator. Has to be a float array of the same size as src. For a fresh total, that means a zeros-initialized float array - which this pack won't conveniently hand you, so you may need to source one from a small custom node or another pack.
  • mask (NPARRAY, optional) - restrict accumulation to part of the image.

Output is a single nparray: the updated accumulator.

Where it sits in a workflow

The realistic use is temporal averaging over a sequence: feed frames in a loop, then divide the final accumulator by the frame count to get the average frame, which is a classic noise-reduction trick for static scenes. That loop requires looping plumbing that stock ComfyUI doesn't do natively, so the honest use case is more like "inside a custom workflow that already iterates frames" than "drop it into a basic txt2img graph". It's a genuine tool, just not a beginner's first pick.

Installing opencv-comfyui

ComfyUI Manager → search "opencv-comfyui", or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Restart ComfyUI. Dependency is OpenCV (plus numpy, torch):

pip install opencv-contrib-python

You likely already have OpenCV from another pack.

Gotchas

  • dst.type() == CV_32F assertion - your dst is uint8. You need a float32 accumulator of the same size; that's non-negotiable.
  • Batch limits - Image2Nparray only accepts batch_size == 1; use ImageFromBatch for video.
  • Size mismatch - src and dst must match in both dimensions and channels, or OpenCV asserts.
Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY
dstNPARRAY
maskoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY