cv2.determinant
Catch a degenerate matrix before it wrecks your graph
- mtx
- float
A determinant is a single number that tells you whether a square matrix can be inverted and how badly it scales space. Zero means singular - the matrix collapses dimensions and any inversion downstream is going to produce infinities. This node computes it, and its niche in a ComfyUI graph is validation: a one-node sanity check between the step that produced a matrix and the step about to consume it.
Input and output
mtx is an NPARRAY-only input - the tooltip is explicit, "a data array (points / matrix), NOT an image". There's no way to wire a Load Image into this. The requirement is narrow and worth repeating because it's a common stumble: the matrix must be square and CV_32FC1 or CV_64FC1 - single-channel float32 or float64. An integer-typed array, a colour image, or a non-square matrix all raise. If your matrix came out of integer data, cast it first (CV Cast Array, or Image → CV Array with the float32 dtype).
The output is a single FLOAT, which wires into any float input in the pack or into a primitive node you can hold onto.
Want to check the arithmetic without opening ComfyUI? The node is a thin wrapper:
python3 -c "import cv2, numpy as np; print(cv2.determinant(np.eye(3, dtype=np.float32)))"
# 1.0
What it's good for in a real graph
Homography validation. cv2.findHomography happily returns a matrix from a degenerate configuration - points that are collinear, or all coplanar, or a match set that's mostly outliers. det ≈ 0 is the cheap tell that the estimate is rubbish, and you can gate the downstream warp on it. This matters more than it sounds: a bad homography doesn't crash, it silently produces a smeared, sheared image that you then spend twenty minutes blaming on the wrong node.
Rotation matrix sanity. A genuine rotation has det = +1. A reflection has det = −1. If you've built or decomposed a rotation - cv2.decomposeProjectionMatrix, an RQ decomposition, a pose assembled from Euler angles - checking the determinant is a one-node verification that you're looking at a rotation and not a mirrored world. (I've written about that sign ambiguity in the projection-matrix node for exactly this reason.)
Essential and fundamental matrix checks. An essential matrix has a zero determinant by construction, and a fundamental matrix has rank 2 - so det ≈ 0 here is confirmation that your estimate has the right algebraic structure, not a warning. If it isn't near zero, something upstream is broken.
Calibration sanity. Confirm an intrinsic matrix K is invertible before you feed it into an undistort or a projection, and confirm it's not something absurd. Combined with the pack's other array nodes, this is the difference between a graph that fails loudly and one that quietly emits garbage.
Install
Manager → Install Custom Nodes → ComfyUI CV (publisher bmad4ever), 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 V3-API ComfyUI; the contrib headless OpenCV wheel is the only dependency, no models involved. The pack is GPL-3.0, forked from geroldmeisinger/opencv-comfyui, largely LLM-generated, and its author is upfront that it isn't production-ready and that support isn't promised. For geometry nodes especially, that means verify on data where you know the answer.
Common issues
- An assertion about type or size. Square, single-channel, float32/float64. Cast or reshape first; the pack's
CV Array ShapeandInspect CV Datanodes tell you what you actually have. - The link refuses to connect.
mtxis NPARRAY-only. Matrices fromCV Find Homography,CV Camera MatrixorCV Parse Matrixare the usual sources. - You got a determinant for a 3×4 projection matrix. Not possible directly - it's non-square. Take the left 3×3 block (the one the RQ decomposition uses) if that's the thing you actually want to test.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| mtx | NPARRAY | input matrix that must have CV_32FC1 or CV_64FC1 type and square size. A data array (points / matrix), NOT an image - only an NPARRAY link is accepted here. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| float | FLOAT | — |