1
votes

I trying to make face recognition using principal component analysis(PCA) combine with support vector machine(SVM). but I'm confused of cv::pca! according to this doc for calculating eigenvectors and eigenvalues we should first calculate covariance matrix of data, then calculate eigenvectors and eigenvalues from covarince matrix. in it's sample codes it does not calculate covariance matrix it just pass data to constructor. so does cv::pca calculate covarience matrix itself? or we should calculate it and pass it to cv::pca constroctor? from dimension of eigenvectors and eigenvalues I guess it does not calculate them. am I right?

1

1 Answers

2
votes

cv::PCA does compute the covariance matrix itself.

See the doc:

For the default constructor:

The default constructor initializes an empty PCA structure. The other constructors initialize the structure and call PCA::operator()().

But in your linked code example, they use the other constructor. For the operator():

performs PCA

The operator performs PCA of the supplied dataset. It is safe to reuse the same PCA structure for multiple datasets. That is, if the structure has been previously used with another dataset, the existing internal data is reclaimed and the new eigenvalues, eigenvectors , and mean are allocated and computed.

The computed eigenvalues are sorted from the largest to the smallest and the corresponding eigenvectors are stored as eigenvectors rows.