cv::PCA(openCV)是否计算数据本身的协方差矩阵?或者我们应该将协方差矩阵传递给它?

Does cv::PCA (openCV) calculate covariance matrix of data itself? or we should pass covarince matrix to it?

我尝试结合使用主成分分析 (PCA) 和支持向量机 (SVM) 进行人脸识别。但我对 cv::pca 感到困惑!根据this doc计算特征向量和特征值,我们应该先计算数据的协方差矩阵,然后从协方差矩阵计算特征向量和特征值。在它的示例代码中,它不计算协方差矩阵,它只是将数据传递给构造函数。那么 cv::pca 会计算协方差矩阵本身吗?或者我们应该计算它并将它传递给 cv::pca 构造函数? 从特征向量和特征值的维度来看,我猜它不会计算它们。我说得对吗?

cv::PCA 会计算协方差矩阵本身。

参见doc

对于默认构造函数:

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

但是在您的链接代码示例中,它们使用了另一个构造函数。 对于 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.