Nodes/opencv-comfyui/OpenCV imread_2
ComfyUI Node

OpenCV imread_2

Imread_2 — the second twin with a dst, and you still don't need it

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV imread_2
  • dst
  • nparray
filename
flags

Here's the whole secret of imread_2: it is byte-for-byte the same generated code as imread_1, which is the same function as imread_0 plus a dst input you should leave empty. OpenCV's type stub lists three overloads of imread; this pack's generator turned each into a node and numbered them, so _1 and _2 both wrap cv2.imread(filename, dst, flags). If you're trying to figure out which one is "the right" imread, the answer is imread_0 - no dst, no temptation, exactly the clean call you want.

That's not to say imread_2 is bad. It works. But the README's advice for every node in this pack is to skip the optional out-parameters (the dst-named ones), because OpenCV fills them instead of allocating - and in a ComfyUI graph the result comes back through the node's own nparray output regardless. Connecting dst buys you nothing and adds a socket that can only confuse you.

What the underlying function does. cv2.imread(filename, flags) reads an image file from a path and decodes it to a BGR uint8 numpy array. In ComfyUI terms it's the file-dialog-free loader: give it an absolute path anywhere the server can read (outside ComfyUI/input), or a path generated by a loop, and get an NPARRAY straight in OpenCV's native format - no Image2Nparray step needed downstream.

Inputs. filename (STRING) - the path as the ComfyUI server sees it; use absolute paths. flags (INT) - 1 (IMREAD_COLOR, default BGR 3-channel), 0 (IMREAD_GRAYSCALE), -1 (IMREAD_UNCHANGED). dst (NPARRAY, optional) - skip it.

Output. One nparray (NPARRAY) - the loaded image. Nparrays2Image turns it back into 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. The usual imread traps: a missing or unreadable file returns None silently, and you'll see the pack's 'NoneType' object has no attribute 'shape' downstream - the path has to exist on the machine running ComfyUI, not on your browser's machine. The output is BGR, so route it through Nparrays2Image before anything expecting RGB. And if you wire dst looking for a behavior change, there isn't one. Use imread_0. This page exists because OpenCV listed the overload; now you know.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
filenameSTRING
flagsINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY