Ask Your Question
-1

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

asked 2019-01-21 02:54:14 -0600

arti gravatar image

updated 2019-01-21 05:53:23 -0600

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: 100
   cols: 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

edit retag flag offensive close merge delete

Comments

read docs first

then, chances, that matlab can read those yml files are close to zero, also, your boken attempt at concatenating files above will only make it worse.

berak gravatar imageberak ( 2019-01-21 04:51:00 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2019-01-21 05:11:59 -0600

berak gravatar image

matlab won't be able to read your yml files, but chances are better with a simple .csv format here, so:

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

        os << format(feature,  cv::Formatter::FMT_CSV);
}
os.close();
edit flag offensive delete link more

Comments

Thanks a lot for reply...why my code not reading all .yml file and properly concatenating data. where i'm doing wrong?? why my code copying -1.32703932e-03 in all 7800 columns and 6 rows ??

arti gravatar imagearti ( 2019-01-21 06:08:57 -0600 )edit

because you're doing everything wrong there. reopening the same filestorage over and over is silly, and you can only use a single "key" like "vocabulary" only once. please read docs again.

berak gravatar imageberak ( 2019-01-21 06:15:42 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-01-21 02:54:14 -0600

Seen: 389 times

Last updated: Jan 21 '19