开发者

convert Matrix of type CV_32FC1 to CV_64FC1

开发者 https://www.devze.com 2023-03-25 19:18 出处:网络
How do I convert a cv::Mat of type CV_32FC1 to the type CV_64FC1 (equivalent to a change from float to double)?

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号