Nodes/opencv-comfyui/OpenCV accumulateWeighted_1
ComfyUI Node

OpenCV accumulateWeighted_1

OpenCV accumulateWeighted_1

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

As with every _1 in this pack, the first thing to know is that accumulateWeighted_1 and accumulateWeighted_0 are the same node. Same src / dst / alpha / optional mask inputs, same dst = (1 - alpha) * dst + alpha * src exponential moving average, same single nparray output. opencv-comfyui emits a numbered node per OpenCV overload, the overloads here share a signature, so you get two copies. Pick one and stay consistent.

Why this one's the keeper

Of the accumulate family, this is the one to actually build a workflow around. It computes a running weighted average of everything you feed it, and because of the (1-alpha) factor old frames never accumulate without bound - the result always stays a proper average. That makes it the natural engine for a background model (average a static scene, then diff new frames against the average to find motion) and for temporal noise reduction on static footage.

The inputs that matter

  • src (NPARRAY) - the new frame.
  • dst (NPARRAY, required) - the running average; float32 and same size as src. uint8 will assert.
  • alpha (FLOAT, required) - weight of the new frame. Small values (0.01–0.1) give a stable, slow-adapting average; larger values react fast but follow noise.
  • mask (NPARRAY, optional) - update the average only where the mask is nonzero.

Output: one nparray - the updated average.

Practical note

The output is a float average, not a display-ready image, so don't wire it straight into Nparrays2Image and expect a crisp photo - you'll usually want to scale or use it as an intermediate for a difference calculation. And since the whole useful pipeline (average, diff, threshold) wants a frame loop, this is friendliest inside a custom video workflow. That's not a ding on the node; it's the nature of temporal processing in ComfyUI.

Installing opencv-comfyui

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

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

Restart ComfyUI. Dependency: opencv-contrib-python (usually already installed).

Gotchas

  • Float accumulator required - dst.type() == CV_32F assertion if you pass uint8.
  • Batch_size == 1 - use ImageFromBatch to slice video batches.
  • Start alpha small - for a background model, 0.01–0.1; too big and moving objects smear into the average.
Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
srcNPARRAY
dstNPARRAY
alphaFLOAT
maskoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY