cv2.getDefaultAlgorithmHint
The one-value node that explains why two identical installs disagree
- int
A whole article for a node that outputs one integer - but it's the integer behind the most maddening class of bug in this pack: the same workflow, the same version numbers, and pixels that differ slightly between two machines.
cv2.getDefaultAlgorithmHint() reports the default implementation hint the OpenCV build applies when a function doesn't get told otherwise. Newer OpenCV versions grew an AlgorithmHint parameter on a pile of functions - cv2.GaussianBlur in this pack has it as an advanced hint input with the values ALGO_HINT_DEFAULT, ALGO_HINT_ACCURATE and ALGO_HINT_APPROX - and the point of it is that some operations have a slower, more accurate implementation and a faster, approximate one. ALGO_HINT_DEFAULT means "you choose, library", and what the library chooses is a build-time and hardware-dependent decision.
So this node tells you which way your install leans. No inputs, one INT out.
Why a graph author cares
If you're chaining deterministic filters and comparing outputs - a regression test, a before/after, a pipeline where step 4 is supposed to reproduce step 4 exactly - bit-exactness matters, and it can change when you swap the cv2 wheel, change machines, or move to a host whose dispatch picks different kernels. Pinning the hint explicitly on the functions that offer it is how you make the result survive that move. This node is how you find out what you were silently relying on.
It's also useful as a fingerprint. If your install returns one value and the friend whose workflow you're reproducing returns another, you've found your discrepancy faster than you'd have found it comparing PNGs.
The output arrives as a bare number
The node returns an INT, not the label. The pack's dropdowns spell the constants by name (ALGO_HINT_DEFAULT, ALGO_HINT_ACCURATE, ALGO_HINT_APPROX), so you can compare the number against the constants on your build with three lines of Python in the same environment ComfyUI uses:
python -c "import cv2; print(cv2.getDefaultAlgorithmHint(), cv2.ALGO_HINT_DEFAULT, cv2.ALGO_HINT_ACCURATE, cv2.ALGO_HINT_APPROX)"
That's the honest way to read it - the mapping between those constants and their integer values isn't something to assume across versions. Wire the INT to a text/display node in the graph and do the comparison once, out of band.
Version note
This is newer API: on an OpenCV 4.8 build the attribute doesn't exist at all. The pack pins a 5.0-era contrib wheel and generates its node menu from what the installed build exposes, so on an older cv2 this node simply won't be in the list - that's the registry telling you the truth about your install rather than a broken pack.
Install
Manager → search ComfyUI CV, or:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"
Restart ComfyUI. Python ≥ 3.12 and a recent ComfyUI on the V3 node API. Nothing to download beyond the wheel.
Where people get burned
- Assuming it changes per run. It's a build constant. ComfyUI may cache it forever, which is fine - it's not a counter and it won't move.
- Reading it as "my install is accurate/approximate". It's the default, i.e. what happens when a node leaves the hint on
ALGO_HINT_DEFAULT. Any node where you set the hint explicitly is unaffected. - Chasing a 1/255 difference with the wrong tool. If two installs disagree slightly, check this and
cv2.getCPUFeaturesLinebefore you re-install anything; differing dispatch is the boring, likely explanation.
Inputs (0)
No inputs
Outputs (1)
| Name | Type | Description |
|---|---|---|
| int | INT | — |