Using OpenCV's pca write and read for saving PCA data [closed]

asked 2016-09-15 15:12:19 -0500

darelet gravatar image

updated 2016-09-15 15:29:40 -0500

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: generated PCA

%YAML:1.0
name: PCA
vectors: !!opencv-matrix
   rows: 2
   cols: 6
   dt: d
   data: [ 6.5094455490411940e-01, 2.6037782196164777e-01,
       -3.9056673294247168e-01, 2.6037782196164777e-01,
       -1.3018891098082389e-01, 5.2075564392329554e-01, 0., 0., 0., 0.,
       0., 0. ]
values: !!opencv-matrix
   rows: 2
   cols: 1
   dt: d
   data: [ 1.4750000000000000e+01, 0. ]
mean: !!opencv-matrix
   rows: 1
   cols: 6
   dt: d
   data: [ 3.5000000000000000e+00, 1., 1.5000000000000000e+00, 3.,
       5.0000000000000000e-01, 7. ]
edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by darelet
close date 2016-09-15 15:45:13.486761

Comments

1