Nodes/opencv-comfyui/OpenCV imread_0
ComfyUI Node

OpenCV imread_0

Load an image from any path on the server, the way cv2 does

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

    imread_0 reads an image file from a path and hands you the OpenCV version of it - a numpy array in BGR, uint8, 0–255. It's the file-loading sibling in this pack: imread for paths, imdecode for in-memory bytes, imcount for "how many images are in this file".

    The honest take on when you need it: ComfyUI's built-in Load Image is a nicer experience for the common case - a file dialog, a preview, images from your input folder. imread_0 exists for the cases that node doesn't cover. You want it when:

    • the file lives outside ComfyUI/input - an absolute path anywhere the server can read, like a mounted dataset folder;
    • you're scripting batch processing of many files whose names a loop produces, rather than hand-picking one from a dialog;
    • you need an image as a raw OpenCV nparray anyway, because everything downstream in this pack expects NPARRAY.

    That last one is the key: this node's output plugs straight into the rest of the pack without an Image2Nparray step, because it's already in OpenCV's native format.

    How it works. A direct cv2.imread(filename, flags) call. Two inputs:

    • filename (STRING) - a filesystem path as the ComfyUI server sees it. Absolute paths are safest; relative paths resolve against the server's working directory. Remember the path is read by the machine running ComfyUI, not your browser.
    • flags (INT) - how to decode. 1 (IMREAD_COLOR) is the default 3-channel BGR read; 0 (IMREAD_GRAYSCALE) if you want it grayscale straight off the disk; -1 (IMREAD_UNCHANGED) preserves the file's native depth and channels. 1 for most work.

    Output. One nparray (NPARRAY) - the loaded image, BGR uint8. Back into ComfyUI-land with Nparrays2Image.

    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; it's under image/OpenCV.

    Where people get burned. The classic one: the file isn't where you think it is. cv2.imread doesn't error on a missing file - it returns None, and this node passes that through, so you get the pack's signature 'NoneType' object has no attribute 'shape' downstream. Check the path on the server's filesystem, not your own. Second: color. The output is BGR, so wire it through Nparrays2Image (which handles BGR→RGB) rather than assuming. Third: the batch rule applies to the image you feed into pack nodes - but imread has no image input, so the batch_size==1 error doesn't apply here; it's one of the cleanest nodes in the pack.

    Which imread variant? This pack has three. imread_0 is the one you actually want: cv2.imread(filename, flags), no out-parameter. imread_1 and imread_2 add a dst out-parameter that the README tells you to ignore anyway. Pick imread_0 and don't look back.

    Categoryimage/OpenCV

    Inputs (2)

    NameTypeDefaultDescription
    filenameSTRING
    flagsINT

    Outputs (1)

    NameTypeDescription
    nparrayNPARRAY