Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to save and load Matx from a file?

When trying to save a cv::Matx to a file using FileStorage, openCV throws some errors which say saving a Matx is not yet implemented. A workaround is to cast the Matx to a cv::Mat when writing:

cv::FileStorage fs("file.xml", cv::FileStorage::WRITE);
cv::Matx33d x;
fs<<"X"<<cv::Mat(x); // file contains x

However, when loading a cv::Matx from file, simply casting it to cv::Mat does not work. I assume the result is not copied, and the Matx is left uninitialized:

cv::FileStorage fs("file.xml", cv::FileStorage::READ);
cv::Matx33d x;
fs>>["X"]>>cv::Mat(x); // x contains gibberish

Is there a simple workaround for this, without resorting to creating temporary cv::Mat's and casting them to Matx after reading?

How to save and load Matx from a file?

When trying to save a cv::Matx to a file using FileStorage, openCV throws some errors which say saving a Matx is not yet implemented. A workaround is to cast the Matx to a cv::Mat when writing:

cv::FileStorage fs("file.xml", cv::FileStorage::WRITE);
cv::Matx33d x;
fs<<"X"<<cv::Mat(x); // file contains x

However, when loading a cv::Matx from file, simply casting it to cv::Mat does not work. I assume the result is not copied, and the Matx is left uninitialized:

cv::FileStorage fs("file.xml", cv::FileStorage::READ);
cv::Matx33d x;
fs>>["X"]>>cv::Mat(x); fs["X"]>>cv::Mat(x); // x contains gibberish

Is there a simple workaround for this, without resorting to creating temporary cv::Mat's and casting them to Matx after reading?