I need to specify a matrix inside a file and then load it onto OpenCV as a Mat
for further processing. How can the cols and lines be specified and where do elements go within the .xml or .yml file?, (for example element A(i,j)
for i from 1 to m lines and for j from 1 to n cols.
In Matlab for example, this is done by loading a .dat file with just the numbers. What is confusing with OpenCV is that the .yml or .xml have some other scripts to them.
Add a comment
|
1 Answer
Read/Write any OpenCV data structure to or from .xml / .yaml file is very simple.
Before you write any content to such file you need to open it and at the end to close it. The XML/YAML data structure in OpenCV is FileStorage
.
string filename = "I.xml";
FileStorage fs(filename, FileStorage::WRITE);
Mat R = Mat_<uchar >::eye (3, 3),
fs << "R" << R; // Write entire cv::Mat
fs["R"] >> R; // Read entire cv::Mat
Check out this link File Input and Output using XML and YAML files