Nodes/ComfyUI CV/Image → CV Array
ComfyUI Node

Image → CV Array

The adapter every OpenCV node in ComfyUI needs

By bmad4ever·Created 3 months ago·Updated 14 days ago· 1
Image → CV Array
  • image
  • nparray
◄color_formatBGR (OpenCV default)►
◄dtypeuint8 (0-255)►
◄batch_index0►

ComfyUI hands you tensors. OpenCV wants cv2 arrays in BGR, usually uint8. Image → CV Array is the little node in between, and if you're using any of the ~470 auto-generated cv2_* nodes in ComfyUI CV, you will wire this one up roughly a hundred times. It's unglamorous and it is load-bearing, which is exactly the shape of the plumbing layer that makes or breaks a graph.

What it is

One input, one output: a ComfyUI IMAGE goes in, a raw ndarray (the pack calls the socket type NPARRAY) comes out. Raw cv2 functions - canny, threshold, matchTemplate, warpAffine, SIFT_create wrappers, the lot - take single images, so this node takes one frame, chosen by batch_index.

The three settings that matter

color_format decides the channel layout: BGR (OpenCV default), RGB, or GRAY. This is not cosmetic. Most cv2 functions assume BGR - ComfyUI's IMAGE is RGB - so leaving it at BGR is the right call for essentially everything, and the conversion is a channel swap rather than a chance to mess up. Switch to GRAY when the function demands a single channel, because that's the classic beginner crash: Canny, threshold, findContours-style edge work and the histogram nodes all want one channel, and they'll throw a cv2 assertion at you if you hand them a three-channel array.

dtype is the other half: uint8 (0-255) or float32 (0-1). Default is uint8 and you should leave it there for classic cv2 operations, because that's what they expect and it's what won't quietly clip. Float32 exists for functions that genuinely want 0–1 float data, and it's the better choice if you're doing arithmetic and don't want the 0–255 wrap-around that turns a bright region into a black one.

batch_index picks which frame of a batch gets converted, clamped to the batch size so you can't blow up with an out-of-range value. If you're feeding a whole video into a cv2 node, be aware that it processes that one frame - the batch-friendly path in this pack is Image Batch → CV Batch, which keeps the whole batch in one 4-D array.

The output, nparray, is what you wire into any low-level wrapper, and after processing you come back the other way with CV Array → Image (or CV Batch → Image Batch if you started batched).

Install

ComfyUI Manager, search the pack title comfyui_cv (bmad4ever/comfyui_cv). Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv

Restart ComfyUI. It needs Python ≥ 3.12 and a recent ComfyUI on the V3 node API - the pack's source is all io.ComfyNode/io.Schema with no NODE_CLASS_MAPPINGS, so an older build won't load it. The actual dependency is one wheel:

pip install "opencv-contrib-python-headless~=5.0.0.93"

Keep it contrib. All four OpenCV wheel variants share the same site-packages/cv2, and dropping a non-contrib wheel in over a contrib one silently wipes the contrib submodules - contrib nodes vanish from the menu with no error. tools/repair_opencv_contrib.py --check / --apply in the pack fixes it.

Where people get burned

  • Nothing downstream accepts your image. You wired IMAGE directly into a cv2_* node. It needs the NPARRAY socket type; add this node.
  • Assertion failed in Canny/threshold. You left color_format on BGR. Set GRAY.
  • Blown-out highlights after arithmetic. The cv2 op expected 0–255 uint8 and you gave it 0–1 floats, or the reverse. Match the dtype to the operation.
  • You got frame 0 and wanted frame 12. That's batch_index, and it clamps rather than erroring, so a wrong value is a silent wrong frame.

One more note in the spirit of honesty: the pack's README is unusually blunt that it was written with heavy LLM assistance, that some pipelines were tuned against specific test images, and that it isn't production-grade without a review of the source. Use it as a lab bench. This node, at least, is a one-line conversion with nowhere to hide a bug.

Categoryimage/CV/low-level

Inputs (4)

NameTypeDefaultDescription
imageIMAGEIMAGE to convert. Only one frame is taken (see batch_index) since raw cv2 nodes work on single images.
color_formatCOMBOBGR (OpenCV default)Most cv2 functions expect BGR; functions like Canny or threshold require a single-channel GRAY image.
dtypeCOMBOuint8 (0-255)Most cv2 functions expect uint8.
batch_indexINT00–4095Which image of the batch to convert (raw cv2 functions operate on single images). Clamped to the batch size.

Outputs (1)

NameTypeDescription
nparrayNPARRAY—