0

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.

1 Answer 1

7

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.