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
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