Ask Your Question

darelet's profile - activity

2016-09-23 02:25:23 -0600 received badge  Enthusiast
2016-09-15 15:29:40 -0600 received badge  Editor (source)
2016-09-15 15:12:19 -0600 asked a question Using OpenCV's pca write and read for saving PCA data

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. ]
2016-08-31 05:27:48 -0600 received badge  Scholar (source)
2016-08-31 05:27:40 -0600 commented answer Issue with meanStdDev() result and Mat channels

I don't know why they couldn't implement such a function like with Matlab, who allow you to calculate the mean/stdev along columns or rows. I'll close this thread but if someone can chip in please use the comments if possible

2016-08-30 12:15:19 -0600 commented question Issue with meanStdDev() result and Mat channels

@berak Maybe let me put it this way, how I can get the mean value per column for a given square matrix using meanStdDev() or a similar function?

2016-08-30 08:38:19 -0600 commented question Issue with meanStdDev() result and Mat channels

@berak Don't know where my initial comment went to.. I'll repeat it. I used reshape to convert the matrix to a 6-channel 2x6, which makes the function calculate the mean/standard deviation for each column individually. If I leave it out then it seems that the matrix is taken as a 1-channel 2x6 matrix and that gives me one value for the mean and standard deviation values calculated across all matrix columns and rows.

2016-08-30 07:48:02 -0600 asked a question Issue with meanStdDev() result and Mat channels

meanStdDev() is not giving the correct calculation of mean and standard. I want it to give mean/stdev for each corresponding column. The code follows,

Mat_<int> C = (Mat_<int>(2,6) << 1, 0, 3, 1, 0, 5, 6, 2, 0, 4, 0, 9), E=Mat::zeros(9, 9, CV_8UC1); 
Mat mn, stdev; 
meanStdDev(C.reshape(C.cols),mn,stdev); 
std::cout << C.reshape(C.cols) << endl<< mn << std::endl;

It gives the following results,

[1, 0, 3, 1, 0, 5; 
 6, 2, 0, 4, 0, 9]

[2.5;
 1;
 0;
 0;
 0;
 0]

You can see that the calculated mean value is corrent only for the first 2 positions