OpenCV absdiff_0
OpenCV absdiff_0
- src1
- src2
- dst
- nparray
You have two images and you want to know, pixel by pixel, how much they differ - a frame from your video and the frame ten seconds later, a mask before and after you cleaned it, the same tile before and after an edit. That's cv2.absdiff, and absdiff_0 is its wrapper. It computes |src1 - src2| per pixel and hands you back a map where bright pixels mean "a lot changed here" and black means "identical". It's the cheapest motion detector that exists, and it's fully deterministic - no model, no seed lottery, nothing to tune except which two images you feed it.
This is one of the 600+ nodes that opencv-comfyui auto-generated straight from OpenCV's own type definitions, so it behaves exactly like the underlying cv2 function: nparrays in, one nparray out, no hand-holding. The pack calls the experience "expect dragons" in its README, which is fair - but absdiff is one of the friendlier dragons because it has only two inputs that matter.
How it works
absdiff_0 wraps cv2.absdiff(src1, src2[, dst]). For every pixel, it subtracts and takes the absolute value, so you get the magnitude of the change regardless of direction - going from black to white scores the same as white to black. On uint8 images the result stays in 0–255, so you can feed it straight into Nparrays2Image and look at it, or push it through a threshold to turn "how much changed" into "changed or not".
The mechanism is why it's the tool for motion and change detection: if you diff consecutive frames of a scene with a fixed camera, everything static cancels out to black and only the moving subject lights up. That's the classic security-camera / object-tracking trick, and you can rebuild it here.
The inputs that matter
- src1 / src2 (NPARRAY) - the two images to compare. Same size and channel count, or it errors out. Both are required.
- dst (NPARRAY, optional) - an OpenCV out-parameter. The README explicitly says to avoid the optional
dstinputs and just read the return value, so leave it unconnected.
The single output is nparray - the absolute-difference map, ready for Nparrays2Image or further OpenCV processing.
Wiring it into a workflow
Keep the pack's standard shape in mind: IMAGE → Image2Nparray → absdiff_0 → Nparrays2Image → IMAGE. Image2Nparray flips RGB to BGR for you and Nparrays2Image flips it back, so colors come out right as long as you don't stick an extra conversion in between. Both conversion nodes require batch_size == 1, so if your video node hands you a batch, run it through ImageFromBatch (length=1) first.
Where people actually reach for this: diffing frames to build a motion mask, comparing a pre/post-processed image to verify an edit did what you expected, or finding the overlap region between two tiles before blending them. That last one is the classic seam-hiding move - absdiff lights up the mismatch zone so you know where to feather.
Installing opencv-comfyui
Install the pack through ComfyUI Manager (search "opencv-comfyui"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
Then restart ComfyUI. The only real dependency is OpenCV itself:
pip install opencv-contrib-python
You almost certainly already have OpenCV installed by some other custom node, so you may not need that line at all.
Common issues
- "Only images with batch_size==1 are supported!" - the Image2Nparray converter refuses batches. Slice with
ImageFromBatchfirst. - Size mismatch assertion - absdiff requires both inputs to be the same dimensions. Resize one side before diffing.
- Everything is black - congratulations, the images are identical, or one of them is a 1-D array that isn't really an image. Check what you're actually feeding it; not every nparray in this pack is a picture.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| src1 | NPARRAY | — | |
| src2 | NPARRAY | — | |
| dstopt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |