Nodes/opencv-comfyui/OpenCV PCACompute_1
ComfyUI Node

OpenCV PCACompute_1

Identical twin of PCACompute_0 — grab either and move on

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

This is the UMat twin of PCACompute_0. Same inputs (data, mean, maxComponents, optional eigenvectors), same outputs (nparray_0 = mean, nparray_1 = eigenvectors), same call to cv2.PCACompute. The pack's generator emits a node for every OpenCV type declaration, and OpenCV declares PCACompute twice - MatLike and UMat - so you get two identical wrappers. There is no reason to prefer one over the other. If you landed here, the article on PCACompute_0 has the full story; this one covers the same ground with the load-bearing details.

What it does

cv2.PCACompute(data, mean, eigenvectors, maxComponents) computes the mean and principal components of a dataset (rows = samples) and returns (mean, eigenvectors). Those two outputs feed straight into PCAProject_0 (to compress) and PCABackProject_0 (to reconstruct), so this node is the model-learning step that the rest of the PCA family consumes. maxComponents sets how many components you keep - the dial between "tiny and lossy" and "bigger and accurate."

The inputs that matter

  • data (NPARRAY) - training samples, one per row.
  • mean (NPARRAY) - required here even though OpenCV can compute it internally. Zero vector is a fine "skip centering" stand-in; real mean is better.
  • maxComponents (INT) - component count.
  • eigenvectors (NPARRAY, optional) - out-parameter, leave it alone.

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 downloads.

Common issues & troubleshooting

  • When in doubt, use PCACompute2 (_0/_2 variants) - it also returns eigenvalues and copes better when samples are fewer than dimensions.
  • Assertion failures are shapes. data and mean column counts must match.
  • Batch rule: batch_size==1 only; use ImageFromBatch if needed.

Same node, different number. The only real decision in the PCACompute family is _0/_1 (max components) vs _2/_3 (retained variance) - and within each pair, the twins are interchangeable.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
dataNPARRAY
meanNPARRAY
maxComponentsINT
eigenvectorsoptNPARRAY

Outputs (2)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY