Nodes/opencv-comfyui/OpenCV findNonZero_1
ComfyUI Node

OpenCV findNonZero_1

FindNonZero's twin — a point list, either way

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV findNonZero_1
  • src
  • idx
  • nparray

OpenCV findNonZero_1 is the UMat twin of findNonZero_0, which means it's the same node under a different name. Same single required input (src, a single-channel NPARRAY), same optional idx out-parameter, same single output: an Nx1x2 array of (x, y) coordinates for every non-zero pixel. The duplicate is a byproduct of the pack auto-generating nodes for both the MatLike and UMat overloads in OpenCV's type stubs. There's nothing to prefer between them.

The substance lives in the _0 article, but here's the quick version: findNonZero scans a single-channel image or mask and hands back where the non-zero pixels are - the raw material for centroid math, bounding boxes, and shape fitting. Feed its output to minAreaRect or fitEllipse and you've got a quick "fit a shape around the bright stuff" pipeline.

What to remember

  • Single channel or nothing. Feed it a 3-channel image and OpenCV asserts (img.type() == CV_8UC1). Convert with cvtColor (code = 6, BGR→GRAY) or feed it a threshold output.
  • The output isn't a picture. It's a point list. Try to preview it through Nparrays2Image and you'll get the pack's classic 'NoneType' object has no attribute 'shape' error, which is the pack's way of telling you to check what the OpenCV function really returns.
  • Batch size 1. Image2Nparray rejects anything bigger - drop an ImageFromBatch node with length = 1 in front if you hit batch_size=2.

Install

Same pack as every node in this family. ComfyUI Manager → search opencv-comfyui → install → restart, or:

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

requirements.txt installs opencv-contrib-python, numpy, torch. The pack imports cv2 at load time; if that import fails (duplicate or missing OpenCV - the guidedFilter error is the tell), none of its hundreds of nodes register.

If a workflow references _1 and you only see _0, just use _0. They're interchangeable, and that pattern applies to every _0/_1 pair in this pack.

Categoryimage/OpenCV

Inputs (2)

NameTypeDefaultDescription
srcNPARRAY
idxoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY