Nodes/opencv-comfyui/OpenCV PCACompute2_1
ComfyUI Node

OpenCV PCACompute2_1

Same as PCACompute2_0, because OpenCV declares everything twice

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

PCACompute2_1 is the UMat twin of PCACompute2_0. Identical signature, identical cv2.PCACompute2 call, identical outputs. The pack auto-generates one node per OpenCV type declaration, OpenCV declares PCACompute2 with both MatLike and UMat types, and you end up with two interchangeable wrappers. There is nothing to choose between them.

So, what you actually have is PCA-with-eigenvalues: feed it a dataset plus a maxComponents count, and it returns the mean, the eigenvectors, and - the thing PCACompute won't give you - the eigenvalues showing how much variance each component explains. That extra array is the practical difference: it's how you see the variance curve and decide where to cut. It also tends to be the more stable choice when your samples are fewer than your dimensions, which is a common shape in image work.

The inputs that matter

  • data (NPARRAY) - training samples, one per row.
  • mean (NPARRAY) - required even though OpenCV can compute it; zero vector skips centering.
  • maxComponents (INT) - component cap.
  • eigenvectors, eigenvalues (NPARRAY, optional) - out-parameters; ignore them.

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

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

  • Prefer PCACompute2 over PCACompute for skinny datasets (fewer samples than dimensions) - that's the documented use case for this family.
  • Assertion failures are shapes: data and mean column counts must match.
  • Batch rule: batch_size==1 only; use ImageFromBatch if needed.

Same node as _0; the real family choice is _0/_1 (max components) vs _2/_3 (retained variance).

Categoryimage/OpenCV

Inputs (5)

NameTypeDefaultDescription
dataNPARRAY
meanNPARRAY
maxComponentsINT
eigenvectorsoptNPARRAY
eigenvaluesoptNPARRAY

Outputs (3)

NameTypeDescription
nparray_0NPARRAY
nparray_1NPARRAY
nparray_2NPARRAY