Nodes/opencv-comfyui/OpenCV imdecode_1
ComfyUI Node

OpenCV imdecode_1

Imdecode_1 — same byte-decoder as _0, numbered because OpenCV overloaded it

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV imdecode_1
  • buf
  • nparray
flags

Straight to it: imdecode_1 and imdecode_0 are the same node. This pack parses OpenCV's type stubs and generates one ComfyUI class per overload, numbered _0, _1, and so on. When the overloads differ, the nodes differ; when they don't - as here - you get two identical twins. Both call cv2.imdecode(buf, flags) with the same argument order and the same output. Use either; there's no reason to prefer one.

The function itself is worth understanding once. cv2.imdecode turns an in-memory buffer of encoded image bytes (the raw PNG/JPEG/WebP payload, as a numpy byte array) into a decoded image - no file path involved. It's the counterpart to imencode_0 (which encodes an image to bytes), and it's the node you reach for when the encoded data already lives in your graph: fetched from an API, produced by an encoder node upstream, pulled out of a database. The whole point is to never write a temp file and never hand OpenCV a path.

Inputs. buf (NPARRAY) - the encoded image data as a byte array. flags (INT) - the decode mode: 1 (IMREAD_COLOR, 3-channel BGR, the default and safe pick), 0 (IMREAD_GRAYSCALE), or -1 (IMREAD_UNCHANGED, preserves the file's native channel count - the one to use for PNGs with alpha or 16-bit data).

Output. One nparray (NPARRAY) - the decoded image in BGR uint8 form. Nparrays2Image converts it back to a ComfyUI IMAGE.

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

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

Restart ComfyUI; the node is under image/OpenCV.

Where people get burned. Feed it an already-decoded image array instead of encoded bytes and you get an assertion error or a silent None. A failed decode surfaces downstream as the README's classic 'NoneType' object has no attribute 'shape' - that error is this pack's signature way of telling you an nparray wasn't actually an image. And keep the color conventions straight: the output is BGR, so wire it through Nparrays2Image (which swaps back to RGB) rather than assuming anything.

Worth saying once more, because every node in this pack carries the same caveat: it's auto-generated, the knobs are raw OpenCV codes with no tooltips, and the author's own tagline is "Expect dragons!". If you're doing simple disk loading, imread_0 or the built-in Load Image is friendlier; imdecode is for the specific case where the bytes are already in your graph.

Categoryimage/OpenCV

Inputs (2)

NameTypeDefaultDescription
bufNPARRAY
flagsINT

Outputs (1)

NameTypeDescription
nparrayNPARRAY