OpenCV trace_0
The node that returns a string instead of an image
- mtx
- literal
cv2.trace computes the trace of a matrix - the sum of the elements on its main diagonal. And here it is, wrapped as a ComfyUI node, outputting a string. This is the pack's auto-generation at its most literal: every top-level OpenCV function got a node whether or not it belongs on a graph, and "sum of the diagonal" is very much a "maybe" for image work. I'll be straight with you: this node is for debugging and for math-heavy geometry workflows, not for making pictures.
Where it shows up in the real world: camera geometry. The trace appears in closed-form solutions for rotation averaging, in essential-matrix math, and in sanity-checking that a matrix is what you think it is (a proper rotation matrix has trace 1 + 2*cos(angle), for instance). If you're building a stereo or pose-estimation pipeline out of this pack's calib3d nodes - triangulatePoints, undistort, the works - a trace check is a cheap way to verify an intermediate matrix before it goes downstream. If you're doing normal generation, there's nothing here for you, and that's fine.
The one input and the odd output
- mtx (NPARRAY) - the matrix to sum the diagonal of.
The single output is literal, and it's typed STRING, not a number. That's the pack's convention for scalar results it couldn't type properly - the value comes back as a string, which is awkward if you wanted to feed it into math downstream. You can read it, you can log it, you can wire it into a text node; you can't do arithmetic on it without conversion. (A trace_1 sibling exists - same function, second overload label, identical behavior.)
Installation
The pack installs once for all its nodes: ComfyUI Manager, search "OpenCV", or git clone https://github.com/geroldmeisinger/opencv-comfyui into ComfyUI/custom_nodes and restart. It needs opencv-contrib-python (pip install opencv-contrib-python; the README's opencv-python-contrib isn't the real package name). Nothing to download, no models.
Common issues
The biggest "issue" is expectation management. trace runs on a matrix, not an image, and it returns a string rather than an array - try to feed the output into Nparrays2Image and you'll hit the README's 'NoneType' object has no attribute 'shape', because a scalar isn't an image and this node doesn't pretend otherwise. Feed it a multi-channel image thinking "matrix" and you'll get whatever the diagonal sum of the raw pixel array happens to be, which is meaningless. Use it where a matrix is genuinely a matrix, and it's a fine little utility. Elsewhere, move on.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| mtx | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| literal | STRING | — |