我需要將一組訓練圖像的OpenCV PCA對象(特徵值,特徵向量)存儲到持久性存儲中,以便稍後重新加載以供測試。我使用OpenCV 2.4功能XML/YAML file storages將我的特徵向量和特徵值矩陣寫入yaml文件。但是,當重新加載文件並將相同的輸入圖像投影到重新加載的PCA空間時,我沒有得到0投影之間的區別嗎?我相信我失去了精確性,但似乎無法弄清楚爲什麼?我根據我的代碼在他的解決方案「Saving pca object in opencv"OpenCV將PCA特徵向量寫入yaml文件,失去精度?
int numPrincipalComponents = db.size()-1;
Mat output1, output2;
PCA pca(matrix, global_mean_vec, CV_PCA_DATA_AS_ROW, numPrincipalComponents);
pca.project(matrix.row(0), output1); //Project first image into orig. PCA
Mat eigenvalues = pca.eigenvalues.clone();
Mat eigenvectors = pca.eigenvectors.clone();
//Write matrices to pca_happy.yml
FileStorage fs("./Train/FileStore/pca_happy.yml", FileStorage::WRITE);
fs << "Eigenvalues" << eigenvalues;
fs << "Eigenvector" << eigenvectors;
fs.release();
//Load matrices from pca_happy.yml
FileStorage fs1("./Train/FileStore/pca_happy.yml", FileStorage::READ);
Mat loadeigenvectors, loadeigenvalues;
fs1["Eigenvalues"] >> eigenvalues;
fs1["Eigenvector"] >> eigenvectors;
fs1.release();
PCA pca2;
pca2.mean = global_mean_vec;
pca2.eigenvalues = loadeigenvalues;
pca2.eigenvectors = loadeigenvectors;
pca2.project(matrix.row(0), output2);
Mat diff;
absdiff(output1, output2, diff);
cout<<sum(diff)[0]<<endl;
通過@link給出一個答案然而不同的是88.4,應該是0,因爲我伸出完全相同的圖像。我需要存儲?特徵向量矩陣中的每一行的任何建議,非常感謝