Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to read sequence of .yml file and concatenate in a single yml file in rows

Hello all, i'm trying to read sequence of.yml files and reshape them in single a single row then trying to concatenate in a single .yml file. here is my snap of code...

for (int i = 1; i <= 6; i++ ) { sprintf_s(filename, "VocabularyLBP/Dictionary%d.yml", i); Mat feature;// , labels);;// = Mat::zeros(1, 100, CV_32FC1); FileStorage fs(filename, FileStorage::READ); fs["vocabulary"] >> feature; feature.convertTo(feature, CV_32FC1); feature = feature.reshape(1, 1);

    trainData.push_back(feature);
    FileStorage fs1("trainData.yml", FileStorage::WRITE);
    fs1 << "vocabulary" << trainData;
    }

i'm not getting error, but getting data like..

vocabulary: !!opencv-matrix rows: 6 cols: 7800 dt: f data: [ -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, %YAML:1.0 -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,........

what wrong i'm doing here why each row and column have same value....

my data was like Data1 %YAML:1.0 Vocabulary: !!opencv-matrix rows: 100 cols: 78 dt: f data: [ 5.49666524e-001, 5.66434860e-001, 4.44352776e-001, 3.23528647e-001, 2.49731302e-001, 9.43774283e-002, 8.07617828e-002, 1.17960289e-001, 6.93683475e-002,....

data2: %YAML:1.0 Vocabulary: !!opencv-matrix rows: 1 cols: 7800 dt: f data: [ 1.19325793e+000, 1.14433956e+000, 1.22386146e+000, 1.20958960e+000, 1.75026524e+000, 5.27490759e+000,...... data3: %YAML:1.0 Vocabulary: !!opencv-matrix rows: 100 cols: 78 dt: f data: [ 3.21339786e-001, 2.84904152e-001, 2.93418944e-001, 2.12616310e-001, 1.51279286e-001, 1.42454490e-001, 1.66635603e-001,...........

etc why not properly getting data in a single file. what is wrong in my code How can i read .yml file in matlab. help please. Thanks

click to hide/show revision 2
None

updated 2019-01-21 03:17:36 -0600

berak gravatar image

How to read sequence of .yml file and concatenate in a single yml file in rows

Hello all, i'm trying to read sequence of.yml files and reshape them in single a single row then trying to concatenate in a single .yml file. here is my snap of code...

for (int i = 1; i <= 6; i++ )
        {
        sprintf_s(filename, "VocabularyLBP/Dictionary%d.yml", i);
       Mat feature;// , labels);;// = Mat::zeros(1, 100, CV_32FC1);
       FileStorage fs(filename, FileStorage::READ);
        fs["vocabulary"] >> feature;
        feature.convertTo(feature, CV_32FC1); 
        feature = feature.reshape(1, 1);

1);

        trainData.push_back(feature);
     FileStorage fs1("trainData.yml", FileStorage::WRITE);
     fs1 << "vocabulary" << trainData;
     }

i'm not getting error, but getting data like..

---
vocabulary: !!opencv-matrix
   rows: 6
   cols: 7800
   dt: f
   data: [ -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
%YAML:1.0
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,........

-1.32703932e-03,........

what wrong i'm doing here why each row and column have same value....

my data was like Data1 Data1

%YAML:1.0
Vocabulary: !!opencv-matrix
   rows: 100
   cols: 78
   dt: f
   data: [ 5.49666524e-001, 5.66434860e-001, 4.44352776e-001,
       3.23528647e-001, 2.49731302e-001, 9.43774283e-002,
       8.07617828e-002, 1.17960289e-001, 6.93683475e-002,....

6.93683475e-002,....

data2:

%YAML:1.0
Vocabulary: !!opencv-matrix
   rows: 1
   cols: 7800
   dt: f
   data: [ 1.19325793e+000, 1.14433956e+000, 1.22386146e+000,
       1.20958960e+000, 1.75026524e+000, 5.27490759e+000,......
data3:

data3:

%YAML:1.0
Vocabulary: !!opencv-matrix
   rows: 100
   cols: 78
   dt: f
   data: [ 3.21339786e-001, 2.84904152e-001, 2.93418944e-001,
       2.12616310e-001, 1.51279286e-001, 1.42454490e-001,
       1.66635603e-001,...........

1.66635603e-001,...........

etc why not properly getting data in a single file. what is wrong in my code How can i read .yml file in matlab. help please. Thanks Thanks

How to read sequence of .yml file and concatenate in a single yml file in rows

Hello all, i'm trying to read sequence of.yml files and reshape them in single a single row then trying to concatenate in a single .yml file. here is my snap of code...

for (int i = 1; i <= 6; i++ )
        {
        sprintf_s(filename, "VocabularyLBP/Dictionary%d.yml", i);
       Mat feature;// , labels);;// = Mat::zeros(1, 100, CV_32FC1);
       FileStorage fs(filename, FileStorage::READ);
        fs["vocabulary"] >> feature;
        feature.convertTo(feature, CV_32FC1); 
        feature = feature.reshape(1, 1);

        trainData.push_back(feature);
        FileStorage fs1("trainData.yml", FileStorage::WRITE);
        fs1 << "vocabulary" << trainData;
        }

i'm not getting error, but getting data like..

---
vocabulary: !!opencv-matrix
   rows: 6
   cols: 7800
   dt: f
   data: [ -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
%YAML:1.0
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,
       -1.32703932e-03, -1.32703932e-03, -1.32703932e-03,........

what wrong i'm doing here why each row and column have same value....

my data was like Data1

%YAML:1.0
Vocabulary: !!opencv-matrix
   rows: 100
   cols: 78
   dt: f
   data: [ 5.49666524e-001, 5.66434860e-001, 4.44352776e-001,
       3.23528647e-001, 2.49731302e-001, 9.43774283e-002,
       8.07617828e-002, 1.17960289e-001, 6.93683475e-002,....

data2:

%YAML:1.0
Vocabulary: !!opencv-matrix
   rows: 1
100
   cols: 7800
78
   dt: f
   data: [ 1.19325793e+000, 1.14433956e+000, 1.22386146e+000,
       1.20958960e+000, 1.75026524e+000, 5.27490759e+000,......

data3:

%YAML:1.0
Vocabulary: !!opencv-matrix
   rows: 100
   cols: 78
   dt: f
   data: [ 3.21339786e-001, 2.84904152e-001, 2.93418944e-001,
       2.12616310e-001, 1.51279286e-001, 1.42454490e-001,
       1.66635603e-001,...........

etc why not properly getting data in a single file. what is wrong in my code How can i read .yml file in matlab. help please. Thanks