Nodes/opencv-comfyui/OpenCV accumulateSquare_0
ComfyUI Node

OpenCV accumulateSquare_0

OpenCV accumulateSquare_0

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

accumulateSquare_0 wraps cv2.accumulateSquare(src, dst[, mask]): it squares every pixel of src and adds that into a running accumulator, so over a sequence the accumulator holds Σ(src²). If you also keep a Σ(src) going with accumulate_0, the two together are all you need to compute the variance and standard deviation of a stack of frames - the honest reason this node exists.

Let me set expectations: in a ComfyUI image graph, this is a statistics primitive, not a visual effect. You won't preview it; you'll read numbers out of it, or combine it with the other accumulate nodes to characterize how a sequence of frames varies. That's genuinely useful for temporal analysis - noise measurement, exposure variance over a video - but it's a niche that assumes you already have frame-loop plumbing.

How it works

The mechanism is the family pattern: dst is a required input that also receives the result, mutated in place. src is squared element-wise (float math, so values can exceed 255 - no saturation), then added to dst. The optional mask restricts which pixels participate: only where the mask is nonzero does dst change. The standing constraint applies: dst must be a float32 array the same size as src, or OpenCV throws its dst.type() == CV_32F assertion.

The inputs that matter

  • src (NPARRAY) - the image whose squares you're accumulating.
  • dst (NPARRAY, required) - the accumulator; float32, same size as src, zeros to start.
  • mask (NPARRAY, optional) - per-pixel gate on accumulation.

Output is a single nparray - the running Σ(src²).

The pair that makes it worth it

The classic combo is accumulate_0 + accumulateSquare_0 over the same frames: variance = Σ(x²)/N − (Σ(x)/N)², and std = √variance. OpenCV's own meanStdDev does this in one call, but this pack doesn't expose a clean wrapper for that, so if you're building the loop yourself these are the primitives. Expect to do the final division and square root outside the pack, since nothing here will hand you a scalar result.

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 (numpy and torch come along too).

Gotchas

  • dst must be float32 - same size as src. uint8 inputs assert immediately.
  • Batch_size == 1 - the conversion nodes refuse batches; use ImageFromBatch.
  • The output isn't an image - a float accumulator feeding Nparrays2Image is a classic "expect dragons" moment. Check shapes before converting.
Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY
dstNPARRAY
maskoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY