Nodes/opencv-comfyui/OpenCV trace_1
ComfyUI Node

OpenCV trace_1

Trace_1 — a math utility wearing an OpenCV costume

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV trace_1
  • mtx
  • literal

trace_1 is the second of two nodes that both compute the matrix trace, and the differences between them are purely cosmetic. OpenCV's type stubs list cv2.trace as overloads; the code generator turned each overload into a node; here you are. Same input, same output, same behavior. If your workflow saved trace_0 and you loaded trace_1, nothing changes except the label.

The underlying function is a one-liner from linear algebra: sum the main diagonal of a matrix. It's not an image operation at all - which is exactly the point of this pack, for better and for worse. The author generated a node for every top-level cv2 function, "Expect dragons," and some of those functions are things like this that only make sense inside a math pipeline. The realistic Comfy use case is camera geometry: verifying that a rotation or essential matrix is well-formed before it feeds triangulatePoints or undistort. A rotation matrix's trace is a function of its angle, so a trace that doesn't look right tells you the matrix got mangled upstream.

What you plug in and what comes out

  • mtx (NPARRAY) - the matrix to trace.

Output is one literal - a STRING, not a number. The pack didn't have a clean scalar type for it, so the result arrives as text. Readable, loggable, fine for eyeballing; not directly arithmetic-able. That output type is the real thing to know about this node, because it shapes everything downstream: it goes into a text or note node, not into math.

Installation

Same pack, same install, once for both twins: ComfyUI Manager (search "OpenCV" or geroldmeisinger/opencv-comfyui), or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes, then restart. Requires opencv-contrib-python (pip install opencv-contrib-python). No models to download.

Common issues

Don't try to turn the output into an image - Nparrays2Image will throw 'NoneType' object has no attribute 'shape' on a scalar, and the README flags that exact error for "nparrays that aren't images." And don't feed it a color image expecting anything meaningful; trace wants a mathematical matrix. There are no composite-literal inputs here (good - no invalid syntax traps), and no grayscale requirement. The node works exactly as advertised; the only real trap is expecting it to be something other than what it is.

Categoryimage/OpenCV

Inputs (1)

NameTypeDefaultDescription
mtxNPARRAY

Outputs (1)

NameTypeDescription
literalSTRING