Add overloaded cv::PCACompute() that returns also the eigenvalues. Useful for Java and Python OpenCV where PCA is not available.

pull/11967/head
catree 7 years ago
parent 9c3ec05825
commit 4dc7e617a4
  1. 10
      modules/core/include/opencv2/core.hpp
  2. 26
      modules/core/src/pca.cpp

@ -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);

@ -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)
{

Loading…
Cancel
Save