0

I'm trying to read sequence of YAML files and reshape them in a single row then trying to concatenate in a single YAML 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 am I doing wrong here? Why do each row and column have the 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 am I not properly getting data in a single file? What is wrong in my code? Why is my code copying -1.32703932e-03 in all 7800 columns and 6 rows?

Anthon
  • 69,918
  • 32
  • 186
  • 246
a.kushwaha
  • 11
  • 2
  • Welcome to [so]. Begging for help is frowned upon, as are thanks. It is helpful to understand what you are doing if you try an make English sentences, starting with a capital and closing with a question mark if they are interrogative sentences. Please post a **complete** and **minimal** program so that we can better make suggestions at what you are doing wrong. – Anthon Jan 21 '19 at 18:40
  • Are you using some YAML parsing/loading library? It looks like it as I have no idea where else the `---` comes from. Your inputs are YAML 1.0 files and e.g. with respect to the `%YAML` directive things have changed significantly between YAML 1.0 and YAML 1.1 (specced over 14 years ago and replaced by YAML 1.2 2009). In 1.0 `---` is a start of document indicator and %YAML follows. In YAML 1.2 it is an end-of-directives indicator and `%YAML` precedes it. If you try and read YAML 1.0 with a 1.2 (or 1.1) parser you might run into trouble. – Anthon Jan 21 '19 at 18:46

0 Answers0