Nodes/opencv-comfyui/OpenCV PCACompute2_3
ComfyUI Node

OpenCV PCACompute2_3

Retained-variance PCA with eigenvalues, UMat twin edition

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV PCACompute2_3
  • data
  • mean
  • eigenvectors
  • eigenvalues
  • nparray_0
  • nparray_1
  • nparray_2
retainedVariance

PCACompute2_3 is the UMat twin of PCACompute2_2 - same signature, same cv2.PCACompute2 call, same three outputs. Pick either. If you want the full walkthrough, the PCACompute2_2 article has it; here's the short version for anyone who landed on this number.

What this node gives you: PCA model-learning with two nice-to-haves bundled in. First, it returns the eigenvalues alongside mean and eigenvectors, so you can see how much variance each principal component explains. Second, it sizes the subspace by a retainedVariance target rather than a component count - set 0.95 and OpenCV keeps as many components as needed to explain 95% of the variance. You set the quality bar; the math picks the axis count. That combination makes it the most intuitive of the PCA learners in the pack, and like the whole PCACompute2 family it's the steadier choice when your samples are fewer than your dimensions.

The returned nparray_0 (mean) and nparray_1 (eigenvectors) are the model consumed by PCAProject_0 and PCABackProject_0; nparray_2 (eigenvalues) is your variance curve.

The inputs that matter

  • data (NPARRAY) - training samples, one per row.
  • mean (NPARRAY) - required by the generated wrapper even though raw OpenCV can compute it; zero vector = skip centering.
  • retainedVariance (FLOAT) - fraction of variance to keep, in (0, 1]. 0.90.99 is the typical band.
  • eigenvectors, eigenvalues (NPARRAY, optional) - OpenCV out-parameters; ignore them.

How to install it

Pack-level install, once:

  • ComfyUI Manager → search opencv-comfyui → Install, restart ComfyUI.
  • Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Requires opencv-contrib-python. No model downloads.

Common issues & troubleshooting

  • retainedVariance out of (0, 1] is the classic mis-set; keep it in range.
  • Shapes: data and mean column counts must match ((-215:Assertion failed)).
  • Batch rule: batch_size==1 only - use ImageFromBatch if Image2Nparray objects.

Same node as _2. Within the PCA family, that means: use the PCACompute2 versions when you want eigenvalues or a skinny dataset, and _2/_3 when you'd rather dial variance than component count.

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
dataNPARRAY
meanNPARRAY
retainedVarianceFLOAT
eigenvectorsoptNPARRAY
eigenvaluesoptNPARRAY

Outputs (3)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY
nparray_2NPARRAY