Nodes/opencv-comfyui/OpenCV seamlessClone_0
ComfyUI Node

OpenCV seamlessClone_0

Paste a subject in and nobody sees the seam

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV seamlessClone_0
  • src
  • dst
  • mask
  • blend
  • nparray
p
flags

seamlessClone_0 is the node people actually search for in this pack, because it does the one compositing trick that looks like magic: drop a cut-out subject into a different background and have the lighting and edges blend so well the seam disappears. It wraps cv2.seamlessClone, OpenCV's Poisson image editing, and it's the classical fix for the "I pasted a person on a new background and it looks like a sticker" problem.

How it works

The mechanism is the reason it beats a plain paste. Instead of copying pixels, Poisson blending solves for a new image whose gradients match the source inside the cloned region, while its pixel values match the destination at the boundary. The result: the interior keeps the source's detail and texture, and the transition to the background is smooth by construction - the local lighting sort of re-flows across the seam. If you've ever used Photoshop's "content-aware" compositing or seen a seamless face or object swap, this is the underlying math. In the KB's post-processing framing it's the compositing primitive that sits between "paste" and "re-generate," and for many background-removal workflows it's the finishing step that makes a clean cut-out actually sit in a scene.

Inputs and outputs

The inputs, and the dragons: src (the image you're cloning, NPARRAY), dst (the destination background, NPARRAY), mask (which part of src to clone - a single-channel 8-bit mask), p (STRING - a Point literal saying where in the destination the center of the cloned region goes, e.g. (512, 512)), and flags (INT). The flags are the flavor: 1 = NORMAL_CLONE (transfers texture and lighting, the default), 2 = MIXED_CLONE (keeps whatever gradient - source or destination - is stronger, great for textures and text), 3 = FEATURE_EXCHANGE (replaces the destination's texture wholesale). Output is a single nparray - the blended result.

The p string trips everyone up: it's parsed with ast.literal_eval, so it must be real Python syntax - (512, 512) with a comma, not 512, 512 or "512 512". Wrong syntax gives you the pack's invalid syntax (<unknown>, line 0) error. The optional blend input is an out-parameter; the README says avoid those, so leave it unwired. And src and dst need matching channel counts, and the mask should be 8-bit grayscale - convert with cvtColor (code 6) if you're feeding a BGR mask.

Installing

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python

Install: ComfyUI Manager → search "opencv-comfyui", or the commands above, then pip install opencv-contrib-python for the dependency. No model downloads - this is pure computation, which is the point; you get professional compositing for free with zero weights.

Verdict

Expectations, honestly stated: this is the most useful node in the pack, but nobody's writing threads about it - the pack has essentially zero community presence, so you're mostly on your own, and the auto-generated UI will not hold your hand. There's also no node in the pack to construct the mask or parse the output, so plan for a mask source and something to consume the NPARRAY. Still, once you've got src/dst/mask/p/flags right, the results are the kind of "how did you do that" compositing that a plain paste can't touch. The _0/_1 variants are the MatLike/UMat overloads and behave identically.

Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
srcNPARRAY
dstNPARRAY
maskNPARRAY
pSTRING
flagsINT
blendoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY