# Revision history [back]

### How do I write into YML format and read it with opencv and C++ ?

I'm following an OpenCV book tutorial to write and read into File Storage. It's supposed to write a file named "test.yml", then store some value in it and read that file again. Here's the code from the book :

#include <iostream>
#include <string>
#include "opencv2/core.hpp"
using namespace cv;
using namespace std;

int main (int, char** argv){
//create writer
FileStorage fs("test.yml", FileStorage::WRITE);

//save an int
int fps = 5;
fs << "FPS" << fps;

//create some Mat sample
Mat m1 = Mat::eye(2,3, CV_32F);
Mat m2 = Mat::ones(3,2, CV_32F);
Mat result = (m1+1).mul(m1+3);

//write result
fs << "Result" << result;

//release file
fs.release();

Mat r;
fs2["Result"] >> r;
cout << r << endl;
fs2.release();
return 0;

}


WHAT HAVE I TRIED :

There's no error when I run the program, but there's no output (blank) and no *.yml file generated. Therefore I don't know where to go from here.

1. According to OpenCV docs, adding "open" is necessary when reading, so I modified into this :

int main (int, char** argv){

//create writer
FileStorage fs, fs2;
fs("test.yml", FileStorage::WRITE);

//...



But still empty result.

2. Then I tried to check if there's actually any data in it. I added checking code :

//create reader

Mat r;
fs2["Result"] >> r;

if (!r.data)
{
//Fails
cout << "Could not open file. " << endl;
return -1;
}
cout << r << endl;
fs2.release();
return 0;


It return "Could not open file". Turn out, there's no *.yml file generated in my working directory. If this information is relevant, I compile using CMake in terminal Ubuntu.

3. Added cout to check if my matrices have the correct value and are actually there.

 cout << "FPS " << fps << endl;

cout << "Matrix One :" <<"\n" << m1 << endl;
cout << "Matrix Two :" <<"\n" << m2 << endl;
cout << "Result :" <<"\n" << result << endl;


The matrices were printed out correctly. But the .*yml file won't be generated.

4. I thought maybe my code has some bugs, so I tried to run example code from OpenCV Docs : XML/YAML Persistence, and I encountered the same thing. I can run the program, there's no error but no *.yml file generated. I've been dealing with this for 2 days, what did I miss here ?

### How do I write into YML format and read it with opencv and C++ ?

I'm following an OpenCV book tutorial to write and read into File Storage. It's supposed to write a file named "test.yml", then store some value in it and read that file again. Here's the code from the book :

#include <iostream>
#include <string>
#include "opencv2/core.hpp"
using namespace cv;
using namespace std;

int main (int, char** argv){
//create writer
FileStorage fs("test.yml", FileStorage::WRITE);

//save an int
int fps = 5;
fs << "FPS" << fps;

//create some Mat sample
Mat m1 = Mat::eye(2,3, CV_32F);
Mat m2 = Mat::ones(3,2, CV_32F);
Mat result = (m1+1).mul(m1+3);

//write result
fs << "Result" << result;

//release file
fs.release();

Mat r;
fs2["Result"] >> r;
cout << r << endl;
fs2.release();
return 0;

}


WHAT HAVE I TRIED :

There's no error when I run the program, but there's no output (blank) and no *.yml file generated. Therefore I don't know where to go from here.here. However, I've been trying several things :

1. According to OpenCV docs, adding "open" is necessary when reading, so I modified into this :

int main (int, char** argv){

//create writer
FileStorage fs, fs2;
fs("test.yml", FileStorage::WRITE);

//...



But still empty result.

2. Then I tried to check if there's actually any data in it. I added checking code :

//create reader

Mat r;
fs2["Result"] >> r;

if (!r.data)
{
//Fails
cout << "Could not open file. " << endl;
return -1;
}
cout << r << endl;
fs2.release();
return 0;


It return "Could not open file". Turn out, there's no *.yml file generated in my working directory. If this information is relevant, I compile using CMake in terminal Ubuntu.

3. Added cout to check if my matrices have the correct value and are actually there.

 cout << "FPS " << fps << endl;

cout << "Matrix One :" <<"\n" << m1 << endl;
cout << "Matrix Two :" <<"\n" << m2 << endl;
cout << "Result :" <<"\n" << result << endl;


The matrices were printed out correctly. But the .*yml file won't be generated.

4. I thought maybe my code has some bugs, so I tried to run example code from OpenCV Docs : XML/YAML Persistence, and I encountered the same thing. I can run the program, there's no error but no *.yml file generated. I've been dealing with this for 2 days, what did I miss here ?

### How do I write into YML format and read it with opencv and C++ ?

I'm following an OpenCV book tutorial to write and read into File Storage. It's supposed to write a file named "test.yml", then store some value in it and read that file again. Here's the code from the book :

#include <iostream>
#include <string>
#include "opencv2/core.hpp"
using namespace cv;
using namespace std;

int main (int, char** argv){
//create writer
FileStorage fs("test.yml", FileStorage::WRITE);

//save an int
int fps = 5;
fs << "FPS" << fps;

//create some Mat sample
Mat m1 = Mat::eye(2,3, CV_32F);
Mat m2 = Mat::ones(3,2, CV_32F);
Mat result = (m1+1).mul(m1+3);

//write result
fs << "Result" << result;

//release file
fs.release();

Mat r;
fs2["Result"] >> r;
cout << r << endl;
fs2.release();
return 0;

}


WHAT HAVE I TRIED :

There's no error when I run the program, but there's no output (blank) and no *.yml file generated. Therefore I don't know where to go from here. However, I've been trying several things :

1. According to OpenCV docs, adding "open" is necessary when reading, so I modified into this :

int main (int, char** argv){

//create writer
FileStorage fs, fs2;
fs("test.yml", FileStorage::WRITE);

//...



But still empty result.

2. Then I tried to check if there's actually any data in it. I added checking code :

//create reader

Mat r;
fs2["Result"] >> r;

if (!r.data)
{
//Fails
cout << "Could not open file. " << endl;
return -1;
}
cout << r << endl;
fs2.release();
return 0;


It return "Could not open file". Turn out, there's no *.yml file generated in my active / project working directory. If this information is relevant, I compile using CMake in terminal Ubuntu.

3. Added cout to check if my matrices have the correct value and are actually there.

 cout << "FPS " << fps << endl;

cout << "Matrix One :" <<"\n" << m1 << endl;
cout << "Matrix Two :" <<"\n" << m2 << endl;
cout << "Result :" <<"\n" << result << endl;


The matrices were printed out correctly. But the .*yml file won't be generated.

4. I thought maybe my code has some bugs, so I tried to run example code from OpenCV Docs : XML/YAML Persistence, and I encountered the same thing. I can run the program, there's no error but no *.yml file generated. I've been dealing with this for 2 days, what did I miss here ?

### How do I write into YML format and read it with opencv and C++ ?

I'm following an OpenCV book tutorial to write and read into File Storage. It's supposed to write a file named "test.yml", then store some value in it and read that file again. Here's the code from the book :

#include <iostream>
#include <string>
#include "opencv2/core.hpp"
using namespace cv;
using namespace std;

int main (int, char** argv){
//create writer
FileStorage fs("test.yml", FileStorage::WRITE);

//save an int
int fps = 5;
fs << "FPS" << fps;

//create some Mat sample
Mat m1 = Mat::eye(2,3, CV_32F);
Mat m2 = Mat::ones(3,2, CV_32F);
Mat result = (m1+1).mul(m1+3);

//write result
fs << "Result" << result;

//release file
fs.release();

Mat r;
fs2["Result"] >> r;
cout << r << endl;
fs2.release();
return 0;

}


WHAT HAVE I TRIED :

There's no error when I run the program, but there's no output (blank) and no *.yml file generated. Therefore I don't know where to go from here. However, I've been trying several things :

1. According to OpenCV docs, adding "open" is necessary when reading, so I modified into this :

int main (int, char** argv){

//create writer
FileStorage fs, fs2;
fs("test.yml", FileStorage::WRITE);

//...



But still empty result.

2. Then I tried to check if there's actually any data in it. I added checking code :

//create reader

Mat r;
fs2["Result"] >> r;

if (!r.data)
{
//Fails
cout << "Could not open file. " << endl;
return -1;
}
cout << r << endl;
fs2.release();
return 0;


It return "Could not open file". Turn out, there's no *.yml file generated in my active / project working directory. If this information is relevant, I compile using CMake in terminal Ubuntu.

3. Added cout to check if my matrices have the correct value and are actually there.

 cout << "FPS " << fps << endl;

cout << "Matrix One :" <<"\n" << m1 << endl;
cout << "Matrix Two :" <<"\n" << m2 << endl;
cout << "Result :" <<"\n" << result << endl;


The matrices were printed out correctly. But the .*yml file won't be generated.

4. I thought maybe my code has some bugs, so I tried to run example code from OpenCV Docs : XML/YAML Persistence, and I encountered the same thing. I can run the program, there's no error but no *.yml file generated. I've been dealing with this for 2 days, what did I miss here ?

### How do I write into YML format and read it with opencv and C++ ?

I'm following an OpenCV book tutorial to write and read into File Storage. It's supposed to write a file named "test.yml", then store some value in it and read that file again. Here's the code from the book :

#include <iostream>
#include <string>
#include "opencv2/core.hpp"
using namespace cv;
using namespace std;

int main (int, char** argv){
//create writer
FileStorage fs("test.yml", FileStorage::WRITE);

//save an int
int fps = 5;
fs << "FPS" << fps;

//create some Mat sample
Mat m1 = Mat::eye(2,3, CV_32F);
Mat m2 = Mat::ones(3,2, CV_32F);
Mat result = (m1+1).mul(m1+3);

//write result
fs << "Result" << result;

//release file
fs.release();

Mat r;
fs2["Result"] >> r;
cout << r << endl;
fs2.release();
return 0;

}


WHAT HAVE I TRIED :

There's no error when I run the program, but there's no output (blank) and no *.yml file generated. Therefore I don't know where to go from here. However, I've been trying several things :

1. According to OpenCV docs, adding "open" is necessary when reading, so I modified into this :

int main (int, char** argv){

//create writer
FileStorage fs, fs2;
fs("test.yml", FileStorage::WRITE);

//...



But still empty result.

2. Then I tried to check if there's actually any data in it. I added checking code :

//create reader

Mat r;
fs2["Result"] >> r;

if (!r.data)
{
//Fails
cout << "Could not open file. " << endl;
return -1;
}
cout << r << endl;
fs2.release();
return 0;


It return "Could not open file". Turn out, there's no *.yml file generated in my active / project working directory. If this information is relevant, I compile using CMake in terminal Ubuntu.

3. Added cout to check if my matrices have the correct value and are actually there.

 cout << "FPS " << fps << endl;

cout << "Matrix One :" <<"\n" << m1 << endl;
cout << "Matrix Two :" <<"\n" << m2 << endl;
cout << "Result :" <<"\n" << result << endl;


The matrices were printed out correctly. But the .*yml file won't be generated.

4. I thought maybe my code has some bugs, so I tried to run example code from OpenCV Docs : XML/YAML Persistence, and I encountered the same thing. I can run the program, there's no error but no *.yml file generated. I've been dealing with this for 2 days, what did I miss here ?

### How do I write into YML YAML format and read it with opencv and C++ ?

I'm following an OpenCV book tutorial to write and read into File Storage. It's supposed to write a file named "test.yml", "test.yml", then store some value in it and read that file again. Here's the code from the book :

#include <iostream>
#include <string>
#include "opencv2/core.hpp"
using namespace cv;
using namespace std;

int main (int, char** argv){
//create writer
FileStorage fs("test.yml", FileStorage::WRITE);

//save an int
int fps = 5;
fs << "FPS" << fps;

//create some Mat sample
Mat m1 = Mat::eye(2,3, CV_32F);
Mat m2 = Mat::ones(3,2, CV_32F);
Mat result = (m1+1).mul(m1+3);

//write result
fs << "Result" << result;

//release file
fs.release();

Mat r;
fs2["Result"] >> r;
cout << r << endl;
fs2.release();
return 0;

}


WHAT HAVE I TRIED :

There's no error when I run the program, but there's no output (blank) and no *.yml file generated. Therefore I don't know where to go from here. However, I've been trying several things :

1. According to OpenCV docs, adding "open" is necessary when reading, so I modified into this :

int main (int, char** argv){

//create writer
FileStorage fs, fs2;
fs("test.yml", FileStorage::WRITE);

//...



But still empty result.

2. Then I tried to check if there's actually any data in it. I added checking code :

//create reader

Mat r;
fs2["Result"] >> r;

if (!r.data)
{
//Fails
cout << "Could not open file. " << endl;
return -1;
}
cout << r << endl;
fs2.release();
return 0;


It return "Could not open file". Turn out, there's no *.yml file generated in my active / project working directory. If this information is relevant, I compile using CMake in terminal Ubuntu.

3. Added cout to check if my matrices have the correct value and are actually there.

 cout << "FPS " << fps << endl;

cout << "Matrix One :" <<"\n" << m1 << endl;
cout << "Matrix Two :" <<"\n" << m2 << endl;
cout << "Result :" <<"\n" << result << endl;


The matrices were printed out correctly. But the .*yml file won't be generated.

4. I thought maybe my code has some bugs, so I tried to run example code from OpenCV Docs : XML/YAML Persistence, and I encountered the same thing. I can run the program, there's no error but no *.yml file generated. I've been dealing with this for 2 days, what did I miss here ?

### How do I write into YAML format and read it with opencv and C++ ?

I'm following an OpenCV book tutorial to write and read into File Storage. It's supposed to write a file named "test.yml", then store some value in it and read that file again. Here's the code from the book :

#include <iostream>
#include <string>
#include "opencv2/core.hpp"
using namespace cv;
using namespace std;

int main (int, char** argv){
//create writer
FileStorage fs("test.yml", FileStorage::WRITE);

//save an int
int fps = 5;
fs << "FPS" << fps;

//create some Mat sample
Mat m1 = Mat::eye(2,3, CV_32F);
Mat m2 = Mat::ones(3,2, CV_32F);
Mat result = (m1+1).mul(m1+3);

//write result
fs << "Result" << result;

//release file
fs.release();

Mat r;
fs2["Result"] >> r;
cout << r << endl;
fs2.release();
return 0;

}


WHAT HAVE I TRIED :

There's no error when I run the program, but there's no output (blank) and no *.yml file generated. Therefore I don't know where to go from here. However, I've been trying several things :

1. According to OpenCV docs, adding "open" is necessary when reading, so I modified into this :

int main (int, char** argv){

//create writer
FileStorage fs, fs2;
fs("test.yml", FileStorage::WRITE);

//...



But still empty result.

2. Then I tried to check if there's actually any data in it. I added checking code :

//create reader

Mat r;
fs2["Result"] >> r;

if (!r.data)
{
//Fails
cout << "Could not open file. " << endl;
return -1;
}
cout << r << endl;
fs2.release();
return 0;


It return "Could not open file". Turn out, there's no *.yml file generated in my active / project working directory. If this information is relevant, I compile using CMake in terminal Ubuntu.

3. Added cout to check if my matrices have the correct value and are actually there.

 cout << "FPS " << fps << endl;

cout << "Matrix One :" <<"\n" << m1 << endl;
cout << "Matrix Two :" <<"\n" << m2 << endl;
cout << "Result :" <<"\n" << result << endl;


The matrices were printed out correctly. But the .*yml file won't be generated.

4. I thought maybe my code has some bugs, so I tried to run example code from OpenCV Docs : XML/YAML Persistence, and I encountered the same thing. I can run the program, there's no error but no *.yml file generated. I've been dealing with this for 2 days, what did I miss here ?