CV Index Batch
Get one frame out of a stack, without it ever erroring
- nparray
- frame
Small node, real job: a batched NPARRAY goes in, one element comes out. (N, H, W, C) plus index=2 gives you (H, W, C). That's it - and that "that's it" is exactly why it earns a page, because in ComfyUI CV the batched arrays are everywhere and a lot of cv2 calls are single-image affairs.
What you'll actually use it for
You went batched on purpose. Image Batch → CV Batch kept a whole clip as [B,H,W,C], or a DNN decode gave you a stack from CV DNN Images From Blob, or CV Unstack Batch handed you a batched array you'd rather sample from. Now one step needs a single image: a preview, a template match, a Haar cascade, a cv2.remap, anything written against one 2-D array. This node is the adapter.
The inputs are minimal by design. nparray is the batched array. index is which element to pull, 0-based, and it is clamped to the valid range - no out-of-bounds error, ever. Set it to 2 on a 2-frame batch and you get frame 1.
That clamping is a genuine design choice and it has two faces. On the plus side, a graph that indexes past the end because the batch size varies between runs keeps working instead of dying. On the minus side, an off-by-one is now invisible: you silently get the wrong frame, and the only symptom is output that looks subtly wrong. If a result doesn't match what you expected, print or preview the frame you're actually indexing before you debug anything downstream.
The output frame is just the single (H,W,C) slice. Wire it into any low-level wrapper, into CV Array → Image to get back to a ComfyUI IMAGE, or into a measurement node like CV Image Moments.
Install
ComfyUI Manager, search the pack title comfyui_cv (bmad4ever/comfyui_cv), or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
Then restart ComfyUI. Two prerequisites people trip on: the pack needs Python ≥ 3.12, and it's written against ComfyUI's V3 node API (io.ComfyNode / io.Schema, no NODE_CLASS_MAPPINGS anywhere), so a recent ComfyUI is mandatory, not a nice-to-have. The single Python dependency:
pip install "opencv-contrib-python-headless~=5.0.0.93"
The version pin matters - the pack is curated against that release and other versions may behave differently. And it must stay the contrib build: every OpenCV wheel shares one site-packages/cv2, so a later non-contrib install silently empties the contrib submodules and contrib nodes vanish from the menu without an error. tools/repair_opencv_contrib.py --check / --apply diagnoses and fixes that.
Notes, briefly
The pack has a whole family of batch helpers, and picking the right one saves wiring: CV Unstack Batch turns a batched array into a ComfyUI list, CV Stack Batch goes the other way, and this node is the "just give me frame 2" case. If you're building a subgraph and want to expose a frame index at the boundary, this is the node to expose.
And the standing caveat from the pack's own README, which applies to everything here: heavy LLM assistance during development, some example pipelines tuned to their sample data, updates unplanned, and an explicit recommendation not to ship it to production without reviewing the source yourself. This one is a slice and a clamp; there's not much to go wrong. The 470 generated wrappers around it are a different risk profile.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| nparray | NPARRAY | Batched array, e.g. (N, H, W, C) from 'CV Unstack Batch' or 'DNN Images From Blob'. | |
| index | INT | 00–4095 | Which element to extract (0-based). Clamped to the batch size. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| frame | NPARRAY | Single (H, W, C) array at the given index. |