OpenCV batchDistance_1
BatchDistance_1 — the duplicate nearest-neighbor node (skip this page)
- src1
- src2
- dist
- nidx
- mask
- nparray_0
- nparray_1
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;
0unless you know better. - crosscheck -
Truekeeps 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.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| src1 | NPARRAY | — | |
| src2 | NPARRAY | — | |
| dtype | INT | — | |
| normType | INT | — | |
| K | INT | — | |
| update | INT | — | |
| crosscheck | BOOLEAN | — | |
| distopt | NPARRAY | — | |
| nidxopt | NPARRAY | — | |
| maskopt | NPARRAY | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| nparray_0 | NPARRAY | — |
| nparray_1 | NPARRAY | — |