Search code examples
pythonopencvpca

Computing eigen values and eigen vectors using PCACompute2


Im using the following code to compute eigen vectors together with eigen values.

mean, eigenvectors, eigenvalues = cv2.PCACompute2(data_pts, mean)

but why am i getting the following error?

AttributeError: module 'cv2' has no attribute 'PCACompute2'

I have installed opencv-contrib-python though using pip but still the error persists. Is there any ways to find eigen values apart from PCACompute2?


Solution

  • Maybe numpy.linalg.eig is what you're looking for? Assuming you're sending your input as a square matrix.

    import numpy as np
    eigenvalues, eigenvectors = np.linalg.eig(M)
    

    You may also want to take a look at an answer to this question: Do non-square matrices have eigenvalues? .