Update pca.cpp

This commit is contained in:
Suleyman TURKMEN 2016-01-26 23:56:25 +02:00
parent 1cd3c6f364
commit c6e6d4c822
2 changed files with 19 additions and 14 deletions

View File

@ -2316,11 +2316,11 @@ public:
The operator performs %PCA of the supplied dataset. It is safe to reuse 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 the same PCA structure for multiple datasets. That is, if the structure
has been previously used with another dataset, the existing internal has been previously used with another dataset, the existing internal
data is reclaimed and the new eigenvalues, @ref eigenvectors , and @ref data is reclaimed and the new @ref eigenvalues, @ref eigenvectors and @ref
mean are allocated and computed. mean are allocated and computed.
The computed eigenvalues are sorted from the largest to the smallest and The computed @ref eigenvalues are sorted from the largest to the smallest and
the corresponding eigenvectors are stored as eigenvectors rows. the corresponding @ref eigenvectors are stored as eigenvectors rows.
@param data input samples stored as the matrix rows or as the matrix @param data input samples stored as the matrix rows or as the matrix
columns. columns.
@ -2400,11 +2400,17 @@ public:
*/ */
void backProject(InputArray vec, OutputArray result) const; void backProject(InputArray vec, OutputArray result) const;
/** @brief write and load PCA matrix /** @brief write PCA objects
*/ Writes @ref eigenvalues @ref eigenvectors and @ref mean to specified FileStorage
void write(FileStorage& fs ) const; */
void read(const FileNode& fs); void write(FileStorage& fs) const;
/** @brief load PCA objects
Loads @ref eigenvalues @ref eigenvectors and @ref mean from specified FileNode
*/
void read(const FileNode& fn);
Mat eigenvectors; //!< eigenvectors of the covariation matrix Mat eigenvectors; //!< eigenvectors of the covariation matrix
Mat eigenvalues; //!< eigenvalues of the covariation matrix Mat eigenvalues; //!< eigenvalues of the covariation matrix

View File

@ -158,15 +158,14 @@ void PCA::write(FileStorage& fs ) const
fs << "mean" << mean; fs << "mean" << mean;
} }
void PCA::read(const FileNode& fs) void PCA::read(const FileNode& fn)
{ {
CV_Assert( !fs.empty() ); CV_Assert( !fn.empty() );
String name = (String)fs["name"]; CV_Assert( (String)fn["name"] == "PCA" );
CV_Assert( name == "PCA" );
cv::read(fs["vectors"], eigenvectors); cv::read(fn["vectors"], eigenvectors);
cv::read(fs["values"], eigenvalues); cv::read(fn["values"], eigenvalues);
cv::read(fs["mean"], mean); cv::read(fn["mean"], mean);
} }
template <typename T> template <typename T>