How do I convert a cv::Mat of type CV_32FC1 to the type CV_64FC1 (equivalent to a change from float to double)?
I am opening a Matrix that was saved as XML (cvSave
) but as a float. This means that the field <dt>
has the value f
in the file. I need to change it to d
to open it. But I'd rather not do this, instead I'd like to open it directly as a Matrix with elements of type double, or convert it later from float to double.
Below is my code for opening the file.
/** Load cv::Mat from XML file. */ cv::Mat loadMat(const std::string filename) { cv::Mat result; cv::FileStorage fs(filename, cv::FileStorage::READ); fs.getFirstTopLevelNode() >> result; return result; }
Okay, I'm a dimwit. Here is how it goes:
There is the function convertTo that does exactly what I want.
Thanks for matrix type conversion in opencv for pointing this out.
Here is how I do it:
cv::Mat A = loadMat("mymat.xml"); // See function loadMat in the question! A.convertTo(A, CV_64F);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With