diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 43da5a9bbe..21be7d7afd 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -1978,10 +1978,20 @@ CV_EXPORTS_W void calcCovarMatrix( InputArray samples, OutputArray covar, CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean, OutputArray eigenvectors, int maxComponents = 0); +/** wrap PCA::operator() and add eigenvalues output parameter */ +CV_EXPORTS_AS(PCACompute2) void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, OutputArray eigenvalues, + int maxComponents = 0); + /** wrap PCA::operator() */ CV_EXPORTS_W void PCACompute(InputArray data, InputOutputArray mean, OutputArray eigenvectors, double retainedVariance); +/** wrap PCA::operator() and add eigenvalues output parameter */ +CV_EXPORTS_AS(PCACompute2) void PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, OutputArray eigenvalues, + double retainedVariance); + /** wrap PCA::project */ CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean, InputArray eigenvectors, OutputArray result); diff --git a/modules/core/src/pca.cpp b/modules/core/src/pca.cpp index 5fdce55cea..0625419a70 100644 --- a/modules/core/src/pca.cpp +++ b/modules/core/src/pca.cpp @@ -360,6 +360,19 @@ void cv::PCACompute(InputArray data, InputOutputArray mean, pca.eigenvectors.copyTo(eigenvectors); } +void cv::PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, OutputArray eigenvalues, + int maxComponents) +{ + CV_INSTRUMENT_REGION() + + PCA pca; + pca(data, mean, 0, maxComponents); + pca.mean.copyTo(mean); + pca.eigenvectors.copyTo(eigenvectors); + pca.eigenvalues.copyTo(eigenvalues); +} + void cv::PCACompute(InputArray data, InputOutputArray mean, OutputArray eigenvectors, double retainedVariance) { @@ -371,6 +384,19 @@ void cv::PCACompute(InputArray data, InputOutputArray mean, pca.eigenvectors.copyTo(eigenvectors); } +void cv::PCACompute(InputArray data, InputOutputArray mean, + OutputArray eigenvectors, OutputArray eigenvalues, + double retainedVariance) +{ + CV_INSTRUMENT_REGION() + + PCA pca; + pca(data, mean, 0, retainedVariance); + pca.mean.copyTo(mean); + pca.eigenvectors.copyTo(eigenvectors); + pca.eigenvalues.copyTo(eigenvalues); +} + void cv::PCAProject(InputArray data, InputArray mean, InputArray eigenvectors, OutputArray result) {