Nodes/opencv-comfyui/OpenCV PCACompute_3
ComfyUI Node

OpenCV PCACompute_3

The retained-variance PCA learner, UMat twin edition

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

PCACompute_3 is the UMat twin of PCACompute_2: same signature, same cv2.PCACompute call, no behavioral difference. The full explanation lives in the PCACompute_2 article - this is the short version for anyone who landed on this number first.

What this node does: it learns a PCA model the "variance" way. You hand it a dataset and a retainedVariance fraction, and it returns the mean and eigenvectors, keeping exactly as many principal components as needed to explain that fraction of the data's variance. 0.95 = "keep enough components that I get 95% of the variance back." OpenCV decides the component count; you just set the quality bar. That's a more intuitive dial than the maxComponents integer used by the _0/_1 twins.

The returned mean + eigenvectors are the model that feeds PCAProject_0 (compress) and PCABackProject_0 (reconstruct) - the encode/decode halves of the PCA pipeline.

The inputs that matter

  • data (NPARRAY) - training samples, one per row.
  • mean (NPARRAY) - required by this generated wrapper even though raw OpenCV can compute it from an empty array. Zero vector works as a "no centering" stand-in.
  • retainedVariance (FLOAT) - fraction of variance to preserve, 0–1. 0.90.99 is the sane band.
  • eigenvectors (NPARRAY, optional) - OpenCV out-parameter; ignore it.

Outputs: nparray_0 (mean), nparray_1 (eigenvectors).

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.
  • Shape errors: data and mean column counts must match ((-215:Assertion failed)).
  • Batch rule: batch_size==1 only - pull a frame with ImageFromBatch if needed.

Pick _2 or _3; they're the same node. And if you'd rather specify component count than variance, the _0/_1 twins do exactly that.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
dataNPARRAY
meanNPARRAY
retainedVarianceFLOAT
eigenvectorsoptNPARRAY

Outputs (2)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY