OpenCV can serialize (save) its objects in JSON, XML or YAML formats. You can use any editor, which understand these formats, in order to read these files, or use OpenCV to download data (de-serialize) from these files. A detailed explanation of how this is done can be found here. In short, to store the data into an XML file, you have to call
cv::FileStorage fs("/path/to/file.xml", cv::FileStorage::WRITE); // Create FileStorage object
cv::Mat cameraM; // Matrix, which you need to save, do not forget to fill it with some data
fs << "cameraMatrix" << cameraM; // Command to save the data
fs.release(); // Releasing the file.
If you want to use JSON or YAML, just change the extension to .json
or .yaml/.yml
- OpenCV will automatically understand your intentions.
The important thing is the command
fs << "cameraMatrix" << cameraM;
the string "cameraMatrix"
is the tag name, under which this matrix will be stored and using which this matrix can be found later in the file.
Note that xml
format will not allow you to use tag names with spaces and some special characters, since only alphanumeric values, dots, dashes and underscores are allowed (see XML
specification for details), while in YAML
and JSON
you can have something like
fs << "Camera Matrix" << cameraM;