Nodes/opencv-comfyui/OpenCV batchDistance_1
ComfyUI Node

OpenCV batchDistance_1

BatchDistance_1 — the duplicate nearest-neighbor node (skip this page)

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV batchDistance_1
  • src1
  • src2
  • dist
  • nidx
  • mask
  • nparray_0
  • nparray_1
dtype
normType
K
update
crosscheck

batchDistance_1 is batchDistance_0 under a second badge. This pack auto-generates a node per OpenCV overload, cv2.batchDistance is declared twice in the type stubs (MatLike and UMat), and the generator never deduplicates - so here we are. Same inputs, same outputs, same behavior. If you've read the _0 page, you're done; come back if you actually need to use it.

For the one-in-a-hundred reader who landed here cold and genuinely needs nearest-neighbor math: this node computes, for every point in src1, the K closest points in src2, and hands you both the distances and the neighbor indices. That's the engine inside feature matching and k-NN classification.

What you'd set

  • src1 / src2 - two NPARRAYs of points or descriptors, one row per item.
  • dtype - output type as an OpenCV int; 5 (CV_32F) is the usual.
  • normType - distance metric; 4 (NORM_L2, Euclidean) is the default you want.
  • K - neighbors to return per query.
  • update - int flag for reusing existing output arrays; 0 unless you know better.
  • crosscheck - True keeps only mutual nearest neighbors, the standard reliability filter for matching.
  • mask, dist, nidx - mask restricts pairs; the other two are out-parameters you can leave unwired.
  • Outputs: nparray_0 (distances) and nparray_1 (indices).

The honest take

This is one of the pack's "dragons" nodes. Three of its inputs are opaque OpenCV integer constants, the outputs are raw matrices (not images - Nparrays2Image will give you the pack's 'NoneType' object has no attribute 'shape' if you try), and the whole thing only pays off if you already understand k-NN. If you just want to compare two images, use compareHist or absdiff. This one is for descriptor matching and point-cloud work, and you'll know it when you need it.

Install

Same as everything in opencv-comfyui:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib

or via ComfyUI Manager (search "opencv-comfyui"), then restart. No models to download; the only pack-level trap is a conflicting OpenCV install (Cannot import name 'guidedFilter' from 'cv2.ximgproc'), solved with a clean reinstall.

Bottom line: _0 and _1 are interchangeable, and this whole pack is rough by design - the README literally says "expect dragons." Read the _0 page for the full run-down, and don't go looking for a difference here.

Categoryimage/OpenCV

Inputs (10)

NameTypeDefaultDescription
src1NPARRAY
src2NPARRAY
dtypeINT
normTypeINT
KINT
updateINT
crosscheckBOOLEAN
distoptNPARRAY
nidxoptNPARRAY
maskoptNPARRAY

Outputs (2)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY