OpenCV PCACompute_3
The retained-variance PCA learner, UMat twin edition
- data
- mean
- eigenvectors
- nparray_0
- nparray_1
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.9–0.99is 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
retainedVarianceout of (0, 1] is the classic mis-set. Keep it in range.- Shape errors:
dataandmeancolumn counts must match ((-215:Assertion failed)). - Batch rule:
batch_size==1only - pull a frame withImageFromBatchif 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.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| data | NPARRAY | — | |
| mean | NPARRAY | — | |
| retainedVariance | FLOAT | — | |
| eigenvectorsopt | NPARRAY | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| nparray_0 | NPARRAY | — |
| nparray_1 | NPARRAY | — |