I am using OpenCV's function for PCA analysis. I want to save and read back the PCA structure using the provided functions. The PCA analysis part is OK, and the function serializes the object to the output file OK. The problem is I cannot read back the serialized object. My code is as follows,
from the main function:
Mat_<double> C = (Mat_<double>(2,6) << 1, 0, 3, 2, 1, 5, 6, 2, 0, 4, 0, 9);
doPCA(vec);
The doPCA function:
string file_name = "/media/femkha/HDB_FemkhaAcer/images2/cplus/pca_data";
const int MAX_COMPONENTS = 2;
{
FileStorage fs(file_name,FileStorage::WRITE);
PCA pca(vec,Mat(),PCA::DATA_AS_ROW,MAX_COMPONENTS);
pca.write(fs);
fs.release();
}
{
FileStorage fs2;
fs2.open(file_name,FileStorage::READ);
FileNode fn = fs2["PCA"];
}
The generated file is as follows: