OpenCV PCACompute2_3
Retained-variance PCA with eigenvalues, UMat twin edition
- data
- mean
- eigenvectors
- eigenvalues
- nparray_0
- nparray_1
- nparray_2
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.9–0.99is 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
retainedVarianceout of (0, 1] is the classic mis-set; keep it in range.- Shapes:
dataandmeancolumn counts must match ((-215:Assertion failed)). - Batch rule:
batch_size==1only - useImageFromBatchifImage2Nparrayobjects.
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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| data | NPARRAY | — | |
| mean | NPARRAY | — | |
| retainedVariance | FLOAT | — | |
| eigenvectorsopt | NPARRAY | — | |
| eigenvaluesopt | NPARRAY | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| nparray_0 | NPARRAY | — |
| nparray_1 | NPARRAY | — |
| nparray_2 | NPARRAY | — |