Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert Matrix of type CV_32FC1 to CV_64FC1

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; } 
like image 547
Unapiedra Avatar asked Aug 02 '11 10:08

Unapiedra


1 Answers

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); 
like image 86
Unapiedra Avatar answered Sep 23 '22 05:09

Unapiedra