私が知る限り、PCAオブジェクトをファイルに保存する一般的な方法はありません。あなたは、固有ベクトル、固有値、平均をファイルに保存し、ロード後に新しいPCAに入れなければなりません。精度を失わないフォーマット、特に平均を使用することを覚えておく必要があります。ここで
は、いくつかのサンプルコードです:
#include "opencv2/core/core.hpp"
#include <iostream>
...
cv::PCA pca1;
cv::PCA pca2;
cv::Mat eigenval,eigenvec,mean;
cv::Mat inputData;
cv::Mat outputData1,outputData2;
//input data has been populated with data to be used
pca1(inputData,Mat()/*dont have previously computed mean*/,
CV_PCA_DATA_AS_ROW /*depends of your data layout*/);//pca is computed
pca1.project(inputData,outputData1);
//here is how to extract matrices from pca
mean=pca1.mean.clone();
eigenval=pca1.eigenvalues.clone();
eigenvec=pca1.eigenvectors.clone();
//here You can save mean,eigenval and eigenvec matrices
//and here is how to use them to make another pca
pca2.eigenvalues=eigenval;
pca2.eigenvectors=eigenvec;
pca2.mean=mean;
pca2.project(inputData,outputData2);
cv::Mat diff;//here some proof that it works
cv::absdiff(outputData1,outputData2,diff);
std::cerr<<sum(diff)[0]<<std::endl; //assuming Youre using one channel data, there
//is data only in first cell of the returned scalar
// if zero was printed, both output data matrices are identical
他の質問を確認して回答を受け入れてください。 – karlphillip