OpenCV patchNaNs_1
PatchNaNs_1 is patchNaNs_0's identical twin — here's why they're both here
- a
- nparray
You opened patchNaNs_1, looked at the inputs, and thought "wait, I just saw this node." You did. patchNaNs_1 has the exact same signature as patchNaNs_0 - same a and val inputs, same nparray output, same behavior. It's not a mistake, and it's not a different algorithm. It's a side effect of how this whole pack is generated, and knowing why makes the whole pack less confusing.
Why there are two of them
The opencv-comfyui pack is auto-generated by parsing OpenCV's type definitions (cv2/__init__.pyi) and turning every top-level function overload into its own node. OpenCV declares nearly every function twice: once with the cv2.typing.MatLike type and once with the UMat type (the OpenCL-backed "unified memory" variant). The generator dutifully emits a node for each overload, numbers them _0, _1, and so on - and since Python's runtime treats MatLike and UMat identically when you call them, you get two byte-for-byte identical wrappers.
So for patchNaNs, _0 is the MatLike overload and _1 is the UMat overload. In practice they do the same thing. The README's phrase is "Expect dragons!" - this is the tame kind: harmless duplication.
What it actually does
cv2.patchNaNs(a, val) replaces every NaN element in the input array with val. That's it. It matters in ComfyUI because a NaN floating through an OpenCV chain - from a division by zero, a log(0), or a warp over empty pixels - survives Nparrays2Image's float32 conversion and poisons the tensor you feed a VAE or ControlNet. Patching to 0.0 before converting is cheap insurance.
Inputs: a (NPARRAY) and val (FLOAT, replacement value - 0.0 is the OpenCV default and the sane choice). Output: nparray, same shape as the input. Choose _0 or _1, it doesn't matter.
How to install it
Pack-level install, once:
- ComfyUI Manager → search opencv-comfyui → Install, restart ComfyUI.
- Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
Requires opencv-contrib-python (the README's pip install opencv-python-contrib is the same package under its alias). No model files.
Common issues & troubleshooting
- Batch size: the pack only supports
batch_size==1. UseImageFromBatch(length=1) ifImage2Nparraycomplains. - Infinity isn't patched.
patchNaNsonly handles NaN, notinf. Overflow has a different cure. - If you see a third numbered twin of a node elsewhere in this pack, same story - the
_0/_1(and sometimes_2/_3) suffixes are just overload numbering, not meaningful variants. ForPCACompute, the numbering does mean something (max-components vs retained-variance overloads) - but for most functions the twins are interchangeable.
If all you need is a NaN-free array before converting back to an image, grab either twin and move on with your life.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| a | NPARRAY | — | |
| val | FLOAT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |