Nodes/opencv-comfyui/Image2Nparray
ComfyUI Node

Image2Nparray

The one node that lets every other OpenCV node see your image

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
Image2Nparray
  • image
  • nparray

If you've ever pasted an OpenCV recipe into ComfyUI and watched it die on the first line, this is the node that fixes it. Image2Nparray is the door into the entire opencv-comfyui pack: it takes a normal ComfyUI IMAGE and hands you the thing every OpenCV function actually wants - a numpy array in BGR, uint8, 0–255, shaped (height, width, channels).

ComfyUI and OpenCV don't speak the same dialect, and it's worth being precise about it because almost every "why is my image wrong" question in this pack traces back to one of these four differences:

| | ComfyUI IMAGE | OpenCV nparray | |---|---|---| | type | torch tensor | numpy ndarray | | shape | (batch, height, width, 3) | (height, width, channels) | | color | RGB | BGR (or grayscale) | | range / dtype | 0.0–1.0 float32 | 0–255 uint8 |

Image2Nparray does the conversion in one line: it takes image[0], moves it to CPU, reverses the channel order (that [..., ::-1] in the source - RGB to BGR), multiplies by 255 and casts to uint8. So the image coming out of this node is a BGR uint8 array, and yes, if you convert it back to a ComfyUI image without going through Nparrays2Image (the pack's opposite-direction node, which swaps BGR back to RGB for you), your reds and blues will be swapped and you'll wonder what's wrong with you.

Inputs / outputs. Just two sockets, and both matter: image (IMAGE) in, nparray (NPARRAY) out. The output plugs into literally every other node in this pack - inpaint_0, imread_0, cvtColor, whatever you're after. There's nothing to configure. The whole node is a conversion.

Installing it is installing the pack. Easiest via ComfyUI Manager - search "opencv-comfyui" and hit install. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

The pack's requirements are opencv-contrib-python, numpy, and torch. You probably already have OpenCV installed by some other custom node; if not, pip install opencv-python-contrib. Restart ComfyUI and you'll find the node under image/OpenCV.

Where people get burned. The big one is the batch size. ComfyUI images carry a batch dimension, and this node refuses anything bigger than one:

Only images with batch_size==1 are supported! batch_size=2

That's the pack author's deliberate design choice - the README says so openly. The fix is ImageFromBatch with length=1 to peel a single frame off your batch before feeding it in. If you feed a batch of frames in expecting to process them all, you'll get this error every time; there's no batch loop behind this node.

The other classic gotcha is assuming the output behaves like a ComfyUI image. It won't: it's a 0–255 uint8 BGR array. Feed it into a node that expects IMAGE and you'll get confusing type errors. And if a function returns something that isn't really an image (the README's example: a 1D array of floats), the downstream Nparrays2Image will die with 'NoneType' object has no attribute 'shape'.

One honest caveat about the whole pack: it was auto-generated by parsing OpenCV's type stubs, so the nodes are ugly, the knobs are raw integers and Python-literal strings, and the author literally labels it "Expect dragons!". If all you need is a Gaussian blur or a gamma curve, the polished image-filter packs (WAS Node Suite, spacepxl's Image Filters) are nicer to use. Reach for this when you need an exact, un-wrapped OpenCV operation that nothing else ships, or when you're prototyping a computer-vision pipeline and want the real cv2 behavior, not a friendly approximation.

Categoryimage/OpenCV

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
nparrayNPARRAY