将类型为CV_32FC1的矩阵转换为CV_64FC1 [英] convert Matrix of type CV_32FC1 to CV_64FC1

查看:127
本文介绍了将类型为CV_32FC1的矩阵转换为CV_64FC1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将CV_32FC1类型的cv :: Mat转换为CV_64FC1类型(相当于从float变为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)?

我要打开一个另存为XML( cvSave )但又是浮点数的矩阵.这意味着字段< dt> 在文件中具有值 f .我需要将其更改为 d 才能将其打开.但是我宁愿不这样做,而是想直接将其作为具有double类型元素的Matrix来打开,或者稍后将其从float转换为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:

有一个功能convertTo正是我想要的.

There is the function convertTo that does exactly what I want.

感谢 opencv中的矩阵类型转换,以指出这一点.

这是我的方法:

cv::Mat A = loadMat("mymat.xml"); // See function loadMat in the question!
A.convertTo(A, CV_64F);

这篇关于将类型为CV_32FC1的矩阵转换为CV_64FC1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆